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