By default Rakus integers are arbitrary sized, theoretically of infinite length. You can't really take the twos complement of an infinitely long number; so, we need to specifically use fixed size integers.
There is a module available from the Raku ecosystem that provides fixed size integer support, named (appropriately enough.) FixedInt.
FixedInt supports fixed bit size integers, not only 8 bit, 16 bit, 32 bit or 64 bit, but ANY integer size. 22 bit, 35 bit, 191 bit, whatever.
Here we'll demonstrate twos complement on a 57 bit integer.
use FixedInt;# Instantiate a new 57(!) bit fixed size integermy \fixedint = FixedInt.new: :57bits;fixedint = (2³⁷ / 72 - 5¹⁷); # Set it to a large valuesay fixedint; # Echo the value to the console in decimal formatsay fixedint.bin; # Echo the value to the console in binary formatfixedint.=C2; # Take the twos complementsay fixedint; # Echo the value to the console in decimal formatsay fixedint.bin; # Echo the value to the console in binary format