Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^7: Converting bytes to floats

by ikegami (Patriarch)
on Apr 18, 2023 at 13:37 UTC ( [id://11151735]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Converting bytes to floats
in thread Converting bytes to floats

Quick question: The string printed is different, but are the values different? (Like, would you get different output for all three if you used printf "%.10000g\n", unpack 'd', pack 'd', sqrt 2?)

For those that might be interested, this linked code stringifies any double using decimal notation (as opposed to scientific notation). It will return the stored number exactly, or you can specify a precision. I'm not sufficiently familiar with the other two formats you mentioned to know whether it will work with them, but I think it will if you specify a precision. The default precision will definitely needs to be adjusted to support those formats.

Replies are listed 'Best First'.
Re^8: Converting bytes to floats
by syphilis (Archbishop) on Apr 18, 2023 at 14:35 UTC
    would you get different output for all three if you used printf "%.10000g\n", unpack 'd', pack 'd', sqrt 2 ?

    As is desirable, it's the same (and correct) output in all three cases:
    D:\>perl -le "printf '%.10000g', unpack 'd', pack 'd', sqrt 2;" 1.4142135623730951454746218587388284504413604736328125
    which, incidentally, is exactly the value of the double precision representation of sqrt 2.

    Cheers,
    Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-18 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found