Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: integer container for float

by BrowserUk (Patriarch)
on Mar 28, 2016 at 11:38 UTC ( [id://1158947]=note: print w/replies, xml ) Need Help??


in reply to integer container for float

You can check that a native int will hold a native double:

use Config; die "Int/double size mismatch" unless $Config{ ivsize } == $Config{ nv +size };

And if you get passed that test, then the following should always work:

$packedDoubleAsInt = unpack 'Q', pack 'd', 3.14159265358979;; print $packedDoubleAsInt;; 4614256656552045841 $unpacked = unpack 'd', pack 'Q', $packedDoubleAsInt;; print $unpacked;; 3.14159265358979 $unpacked = unpack 'd', pack 'Q', 4614256656552045841;; print $unpacked;; 3.14159265358979

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-24 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found