Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
$num = int $num; You can get the same effect with $num |= 0; ...but... why? Why would you want two's complement behavior in other bases? Truncating at $n bits is mathematically equivalent to: $num %= 2 ** $n;That's only meaningful for base-2. You can truncate at $n base-$b digits using this: $num %= $b ** $n;So -1 becomes 999999 in base-10 or 666666 in base-7. If you want, you can pick a big number of digits that still fits in a double-precision float like this: $num %= $base ** int(36.73/log($base));In reply to Re^3: Math::Base - arithmetics with baseX integers (OP updated)
by no_slogan
|
|