The documentation for pack says there's no builtin way to do it:
  Real numbers (floats and doubles) are in
  the native machine format only; due to the
  multiplicity of floating formats around,
  and the lack of a standard "network" rep­
  resentation, no facility for interchange
  has been made.  This means that packed
  floating point data written on one machine
  may not be readable on another - even if
  both use IEEE floating point arithmetic
  (as the endian-ness of the memory repre­
  sentation is not part of the IEEE spec).

  See also the perlport manpage.

I don't really know much about the machine format of floating point numbers, but if the only problem is endianness, unpacking as characters, reversing them, putting them back together, and then interpreting them as native format might work. Something like this:

#!/usr/bin/perl my $f = "3.6"; my $floatpack = pack("d",$f); my $floatpack2 = pack("c*",reverse unpack("c*",$floatpack)); $f2 = unpack("d",$floatpack2); print "f2=$f2\n"; my $floatpack3 = pack("c*",reverse unpack("c*",$floatpack2)); $f3 = unpack("d",$floatpack3); print "f3=$f3\n";

In reply to Re: Unpacking Floating Point on architectures with different endians by sgifford
in thread Unpacking Floating Point on architectures with different endians by HaveBlue

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.