For curiosity and as i have a new license i asked ChatGPT:

#!/usr/bin/env perl + + + for m +y $val (qw(1 -1 2 -2 1/3 -1/3)) { my ($s, $e, $m) = double_to_bin_parts(eval $val); printf "%5s: sign=%s exp=%s mantissa=%s\n", $val, $s, $e, $m; } for my $expr (qw(1 -1 2 -2 1/3 -1/3)) { my $val = eval $expr; my ($s, $e, $m) = double_to_bin_parts($val); printf "%5s %.13a\n %s %s %s\n", $expr, $val, $s, $e, $m; } sub double_to_bin_parts { my $n = shift; my $bits = unpack "B64", pack "d>", $n; my $sign = substr $bits, 0, 1; my $exp = substr $bits, 1, 11; my $mantissa = substr $bits, 12, 52; return ($sign, $exp, $mantissa); } __END__ 1: sign=0 exp=01111111111 mantissa=00000000000000000000000000000000000 +00000000000000000 -1: sign=1 exp=01111111111 mantissa=0000000000000000000000000000000000 +000000000000000000 2: sign=0 exp=10000000000 mantissa=0000000000000000000000000000000000 +000000000000000000 -2: sign=1 exp=10000000000 mantissa=0000000000000000000000000000000000 +000000000000000000 1/3: sign=0 exp=01111111101 mantissa=010101010101010101010101010101010 +1010101010101010101 -1/3: sign=1 exp=01111111101 mantissa=01010101010101010101010101010101 +01010101010101010101 1 0x1.0000000000000p+0 0 01111111111 0000000000000000000000000000000000000000000000000000 -1 -0x1.0000000000000p+0 1 01111111111 0000000000000000000000000000000000000000000000000000 2 0x1.0000000000000p+1 0 10000000000 0000000000000000000000000000000000000000000000000000 -2 -0x1.0000000000000p+1 1 10000000000 0000000000000000000000000000000000000000000000000000 1/3 0x1.5555555555555p-2 0 01111111101 0101010101010101010101010101010101010101010101010101 -1/3 -0x1.5555555555555p-2 1 01111111101 0101010101010101010101010101010101010101010101010101

In reply to Re: Introspection into floats/NV by karlgoethebier
in thread 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.