http://qs321.pair.com?node_id=11108835


in reply to Re^4: Can I access and use UV types from perl?
in thread Can I access and use UV types from perl?

In a sense am I being a little bit confused around what Devel:Peek is telling me

If you want to dive into that rabbit hole, see perlguts and the rest of the internals documentation, although be warned, that's not light reading.

These are actually UV values then? but Perl is storing them as IV's.

Those values will fit fine into a signed integer, so as per dave_the_m's explanation, Perl has no need to upgrade them to a UV. It might be interesting to note that Perl can store pretty big integer values. As per ikegami's post here:

  1. Largest integer value that can be stored as a signed integer: ~0 >> 1 (on my machine: 9,223,372,036,854,775,807), and the smallest: -(~0 >> 1)-1
  2. Largest integer value that can be stored as an unsigned integer: ~0 (on my machine: 18,446,744,073,709,551,615)
  3. All integer values from 0 to this number can be stored without loss as a floating point number: $Config{nv_overflows_integers_at} (on my machine: 9,007,199,254,740,992)
two's complement

One of the things that really helped it click for me back then was this graphic, along with looking at different 2's complement mathematical operations (Update 2: as I showed in my reply below):

0 -1 0000 1 1111 0001 -2 2 1110 0010 -3 3 1101 0011 -4 4 1100 0100 -5 5 1011 0101 -6 6 1010 0110 -7 7 1001 -8 0111 1000

Update: In the graphic I accidentally wrote "8" when it should have been "-8", sorry, fixed.