in reply to Re^2: [OT] Endianness and extended precision (80-bit) long doubles
in thread [OT] Endianness and extended precision (80-bit) long doubles

I am not sure that I can help. current Pack docs. I am on Perl 5.24 and it appears to me that you are using a feature from Perl 5.30? This "D" option to pack() appears in red in my browser.

If Perl source code of:

$ perl -le 'print unpack "h*", pack "D", sqrt 2;' 4846ed9f333f405bfff3000000000000
works? I am also unsure about what will happen on a different architecture. My main machine is Intel (little endian). I have a Raspberry PI which I think is big endian, but I have a lot of hardware cables to screw around with to get it working. Sorry.
D A float of long-double precision in native format. (Long doubles are available only if your system supports long double values _and_ if Perl has been compiled to support those. Raises an exception otherwise. Note that there are different long double formats.) h A hex string (low nybble first). H A hex string (high nybble first).

Replies are listed 'Best First'.
Re^4: [OT] Endianness and extended precision (80-bit) long doubles
by AnomalousMonk (Archbishop) on Aug 25, 2019 at 01:57 UTC

    Quoth  perldoc -f pack on my 5.8.9 Perl:

    D   A long double-precision float in the native format.
        (Long doubles are available only if your system supports long
        double values _and_ if Perl has been compiled to support those.
        Causes a fatal error otherwise.)
    Also see pack. I'm not sure about the red coloration; maybe it flags a feature not supported by all word widths/compilation options. (Actually, I suspect a documentation problem since everything in the table (update: including things like  x X @ that are as old as the hills) from line 41 on is both red and italic.)


    Give a man a fish:  <%-{-{-{-<

      Long doubles are available only if your system supports long double values _and_ if Perl has been compiled to support those.

      Yes - I ran the one liner on a build of perl-5.30.0 whose NV was long double.
      Not sure how far back the "D" option goes, but it's available in 5.8.8 onwards, at least.

      With recent perls we can ask for either little endian or big endian outputs - eg (on Windows):
      C:\_32>perl -le "print unpack 'h*', pack 'D<', sqrt 2;" 4846ed9f333f405bfff3000000000000 C:\_32>perl -le "print unpack 'h*', pack 'D>', sqrt 2;" 000000000000f3ff5b403f339fed4648
      However, I think the "big endian" output given here is simply the reverse of what was found on my machine.
      I don't think there's any basis to assume that it displays what's stored on an actual big endian machine.

      Cheers,
      Rob
      Yes, this red color gave me pause. Since this D feature appears in 5.8.9, I have no idea what the difference in text color means. Maybe if nobody knows what it means, the red color should be removed as a doc fix?

      oh...I see .. perhaps the red means that Perl has to be compiled in a certain way for the feature to "work"? Right now I'm using Perl 25.24 compiled for 64 bit. I suspect that means that long double is available? Almost all of my work is with integers and text. as another "oh...", I remember some benchmark testing that a Phd student did for me from ASM class on float performance with modern Intel processors. There are more transistors in the math unit than in the main CPU. The result was that float operations are about the same as integer ops which surprised me.

        ... I have no idea what the difference in text color means.

        I strongly suspect this is just a documentation bug. As I wrote here, the red/italic rendering appears at a certain line and continues to the end of the table. The template operators (symbols?) (update: specifiers?) so highlighted include ancient  x X @ operators. This highlighting is present even in the earliest on-line documentation: 5.6.0!

        Update: The red/italic highlighting always appears at the line

        d     A double-precision float in the native format.
        even though the layout of the template specifier table changes over documentation versions so that the number of this line changes: line 46 in 5.6.0; line 41 in 5.30.0. (Update: I also don't see any note in the documentation assigning any special meaning to red and/or italic highlighting.)


        Give a man a fish:  <%-{-{-{-<