in reply to Re^5: Converting bytes to floats
in thread Converting bytes to floats
On a perl whose nvtype is the 80-bit extended precision long double:D:\>perl -le "print unpack 'd', pack 'd', sqrt 2;" 1.4142135623731
On a perl whose nvtype is either the IEEE 754 long double or the __float128:D:\>perl -le "print unpack 'd', pack 'd', sqrt 2;" 1.41421356237309515
You might think that the differences in those 3 one liners occur because pack 'd', sqrt 2 has returned different bytes in each of those 3 one liners, but that's not so.D:\>perl -le "print unpack 'd', pack 'd', sqrt 2;" 1.41421356237309514547462185873883
On a perl whose nvtype is the 80-bit extended precision long double:D:\>perl -le "print 'WTF' if (unpack 'd', pack 'd', sqrt 2) != 1.41421 +35623731;" WTF
On a perl whose nvtype is either the IEEE 754 long double or the __float128:D:\>perl -le "print 'WTF' if (unpack 'd', pack 'd', sqrt 2) != 1.41421 +356237309515;" WTF
3 different renditions of the same value - none of them accurate.D:\>perl -le "print 'WTF' if (unpack 'd', pack 'd', sqrt 2) != 1.41421 +356237309514547462185873883;" WTF
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Converting bytes to floats
by ikegami (Patriarch) on Apr 18, 2023 at 13:37 UTC | |
by syphilis (Archbishop) on Apr 18, 2023 at 14:35 UTC |