Integer literals
Posted: Mon Oct 15, 2012 8:02 pm
Cobra now handles int literals outside the signed 32-bit range with having to specify a suffix (eg, 0xffffffff_u32) as seen here:
The type inference is taken straight from C#. The type of the int literal is the first in this list whose range can contain the literal:
int, uint, int64, uint64
You can still use the suffixes (suffices?) if you like; they're not going away. They can also still be useful for smaller values like 0xFF_u8.
class A
def foo
a = 0xfffffff
assert a.typeOf is int32
b = 0xffffffff
assert b.typeOf is uint32
c = 0xfffffffff
assert c.typeOf is int64
d = 0xffffffffffffffff
assert d.typeOf is uint64
def bar
a = 268_435_455
assert a.typeOf is int32
b = 4_294_967_295
assert b.typeOf is uint32
c = 68_719_476_735
assert c.typeOf is int64
d = 18_446_744_073_709_551_615
assert d.typeOf is uint64
The type inference is taken straight from C#. The type of the int literal is the first in this list whose range can contain the literal:
int, uint, int64, uint64
You can still use the suffixes (suffices?) if you like; they're not going away. They can also still be useful for smaller values like 0xFF_u8.