LanX has asked for the wisdom of the Perl Monks concerning the following question:
I was surprised to find out that 27**(1/3) == int 27**(1/3) and tried to introspect what the double float in the NV contains. I spend hours fiddling with printf , pack , unpack and (worst) the bit-order on intel processors to create this
(compare https://bartaz.github.io/ieee754-visualization/ )
$ perl printf "%5s %.13a\n %s\n", $_, eval($_), unpack("B*",pack("F>",ev +al $_)) for qw(1 -1 2 -2 1/3 -1/3) __END__ 1 0x1.0000000000000p+0 0011111111110000000000000000000000000000000000000000000000000000 -1 -0x1.0000000000000p+0 1011111111110000000000000000000000000000000000000000000000000000 2 0x1.0000000000000p+1 0100000000000000000000000000000000000000000000000000000000000000 -2 -0x1.0000000000000p+1 1100000000000000000000000000000000000000000000000000000000000000 1/3 0x1.5555555555555p-2 0011111111010101010101010101010101010101010101010101010101010101 -1/3 -0x1.5555555555555p-2 1011111111010101010101010101010101010101010101010101010101010101
2 questions:
Platform: osname=linux osvers=6.1.0 archname=x86_64-linux-gnu-thread-multi Compiler: cc='x86_64-linux-gnu-gcc'
tested on my ARM mobile which has another endianess, and got the same result
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Introspection into floats/NV
by ikegami (Patriarch) on Jun 03, 2025 at 16:03 UTC | |
by syphilis (Archbishop) on Jun 03, 2025 at 22:33 UTC | |
by LanX (Saint) on Jun 03, 2025 at 16:17 UTC | |
by ikegami (Patriarch) on Jun 03, 2025 at 16:32 UTC | |
by LanX (Saint) on Jun 03, 2025 at 16:55 UTC | |
by ikegami (Patriarch) on Jun 03, 2025 at 18:44 UTC | |
| |
Re: Introspection into floats/NV
by karlgoethebier (Abbot) on Jun 04, 2025 at 14:02 UTC | |
by LanX (Saint) on Jun 04, 2025 at 14:09 UTC | |
by karlgoethebier (Abbot) on Jun 04, 2025 at 14:28 UTC | |
by LanX (Saint) on Jun 04, 2025 at 15:52 UTC | |
by ikegami (Patriarch) on Jun 04, 2025 at 17:50 UTC | |
| |
by karlgoethebier (Abbot) on Jun 04, 2025 at 17:00 UTC | |
|