Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Can I access and use UV types from perl?

by syphilis (Archbishop)
on Nov 17, 2019 at 22:53 UTC ( [id://11108839]=note: print w/replies, xml ) Need Help??


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

use_integer literally turns all the values into IV's. For me that is exactly a counterexample of what I want to be able to do.

If you want to turn all signed integer values into unsigned integer values:
use strict; use warnings; for(-3 .. 3) { print s2u($_), "\n"; } sub s2u { sprintf("%u", $_[0]) + 0; } __END__ OUTPUT: 18446744073709551613 18446744073709551614 18446744073709551615 0 1 2 3


Cheers,
Rob

Replies are listed 'Best First'.
Re^4: Can I access and use UV types from perl?
by Don Coyote (Hermit) on Nov 17, 2019 at 23:32 UTC

    The negative numbers come out as UV's but the positive numbers come out as IV's

    for( -1 .. 1) { print s2u($_), "\n"; } sub s2u { Dump sprintf("%u", $_[0]) + 0; } =head1 output SV = IV(0x732998) at 0x73299c REFCNT = 1 FLAGS = (PADTMP,IOK,pIOK,IsUV) UV = 4294967295 SV = IV(0x732998) at 0x73299c REFCNT = 1 FLAGS = (PADTMP,IOK,pIOK) IV = 0 SV = IV(0x732998) at 0x73299c REFCNT = 1 FLAGS = (PADTMP,IOK,pIOK) IV = 1 =cut
      The negative numbers come out as UV's but the positive numbers come out as IV's

      Yes, and that's why I was careful to state that it converted "signed integer values" to "unsigned integer values" (as opposed to converting IVs to UVs).

      Does it matter that the IsUV flag is not set for values less than or equal to MAX_INT (which is 9223372036854775807 on my machine, and 4294967295 on yours)?
      If so then you face a significant problem - AFAIK there's no way to set the IsUV flag for an integer whose value <= MAX_INT.
      And perl won't call it a "UV" unless the IsUV flag is set.
      Essentially, the IsUV flag (and also the term "UV") indicates that it's a positive integer whose value is greater than MAX_INT.

      You might be able to turn the IsUV flag on for all positive IVs via XS or Inline::C.
      I don't know if it's possible - if it is possible then I don't know what it would break, or even if the IsUV flag could be made to stick when the value <= MAX_INT.

      Cheers,
      Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108839]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-18 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found