Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by dave_the_m (Monsignor)
on Nov 17, 2019 at 18:07 UTC ( [id://11108823]=note: print w/replies, xml ) Need Help??


in reply to Can I access and use UV types from perl?

When a value becomes too big to store as a signed integer, perl automatically upgrades it to an unsigned integer (technically it sets the SVf_IVisUV flag on the SV). If the value becomes too large even for that, then the SV is upgraded to an NV. This is all automatic and you shouldn't have to do anything yourself (unless you're using an ancient version of perl).

Try running

perl -MDevel::Peek -e'$x=(1<<60)-1; for (1..6) { Dump $x; $x = $x *2 + + 1}'
If you want something more than this, you'll have to explain your need better.

Dave.

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

    dave_the_m I see the lowercase f there making me think floats, yikes. oh, its a flag :smile.

    The automagic of Perl values is a great thing, which I value immensely. Please see Re^2: Can I access and use UV types from perl? for a substantial waffle regarding my deeper motives for this expiditionary embarkation.

    On one level I want to be able to say I am adding natural numbers together and be speaking truthfully, rather than saying that, but actually what is happening is that I am adding a subset of integers together.

    Looking at the output. There does seem to be some kind of interplay between the size of the storage unit and the kind of number that Perl assumes the user is wanting to use. That is interesting.

      On one level I want to be able to say I am adding natural numbers together and be speaking truthfully, rather than saying that, but actually what is happening is that I am adding a subset of integers together.

      Then maybe use bignum or bigrat, at a significant performance cost.

        The main sense I am getting from this, is that Perl is all about the storage.

        bignum still appears to store the value as an IV though. and converting a number into a rat is the same problem only stepped up to a relationship between Rationals and Naturals, the Natural numbers now being a subset of Rationals rather than a subset of Integers.

        #use bignum; =head1 output SV = PVAV(0x6fb404) at 0x6fa59c REFCNT = 1 FLAGS = () ARRAY = 0x2ce1c64 FILL = 1 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = IV(0x25bfd30) at 0x25bfd34 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 4967296 Elt No. 1 SV = IV(0x6fa578) at 0x6fa57c REFCNT = 1 FLAGS = (IOK,pIOK) IV = 429 =cut

        Interestingly when I was hacking MvT attempting to use hashkeys to represent natural numbers i kept getting (FAKE) flags, maybe there's something in that. Also storing bitfields as hashkeys has unexpected results.

        It would seem that some kind of overloading solution may be the way to go, let Perl handle the storage, but overload the operations with XSUBS that do type checking/coercion. Or even straight up Inlining C.

Log In?
Username:
Password:

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

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

    No recent polls found