in reply to Re^6: Can I access and use UV types from perl?
in thread Can I access and use UV types from perl?
Sorry, I'm afraid I don't follow... but since you mention the high bit, note how in two's complement, the high bit is basically the sign bit. And the other nice thing is that the binary math still works well:
- -8+1 is 1000+0001, which =1001, which is -7
- -2-2 is 1110+1110, which =11100, drop the overflow and 1100 is -4
- -2+5 is 1110+0101, which =10011, drop the overflow and 0011 is 3
Of course, there are still overflow issues, e.g. 7+1 turns out as -8, but those will always happen with any fixed number of bits. Of course, the advantage of Perl's scalars here is that they will upgrade themselves automatically! (At the risk of losing some precision)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^8: Can I access and use UV types from perl?
by Don Coyote (Hermit) on Nov 18, 2019 at 00:52 UTC | |
by dave_the_m (Monsignor) on Nov 18, 2019 at 09:24 UTC | |
by Don Coyote (Hermit) on Nov 18, 2019 at 20:55 UTC |
In Section
Seekers of Perl Wisdom