Hi

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'

update

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


In reply to Introspection into floats/NV by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.