The UInt
is defined as a subset of Int
:
my of Int where ;
Consequently, it cannot be instantiated or subclassed; however, that shouldn't affect most normal uses.
Some examples of its behavior and uses:
say UInt ~~ Int; # OUTPUT: «True» my UInt = 0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ffff; # 64-bit unsigned value say .base(16); # OUTPUT: «FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF» (32 digits) ++;say .base(16); # OUTPUT: «100000000000000000000000000000000» (33 digits!) my Int = ;say .base(16); # same as above say .^name; # OUTPUT: «Int» - UInt is a subset, so the type is still Int. say .^name; # OUTPUT: «Int» # Difference in assignment my UInt = 5; # nothing wrong my UInt = -5; # Exception about failed type check my UInt = 0;--; # Exception again CATCH ;# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $b; expected UInt but got Int (-5)» # Non-assignment operations are fine my UInt = 0;say - 3; # OUTPUT: «-3»