Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by Don Coyote (Hermit)
on Nov 17, 2019 at 23:32 UTC ( [id://11108842]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^5: Can I access and use UV types from perl?
by syphilis (Archbishop) on Nov 18, 2019 at 00:31 UTC
    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://11108842]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found