[Pdx-pm] PowerPC and little-endian
Austin Schutz
tex at off.org
Wed Mar 1 09:42:11 PST 2006
On Tue, Feb 28, 2006 at 11:11:40PM -0800, jerry gay wrote:
> On 2/28/06, Eric Wilhelm <scratchcomputing at gmail.com> wrote:
> > Hi all,
> >
> > Since I'm in the minority of non-mac owners around here, maybe you all
> > can fill me in on this whole dual-mode software-switched rumor about
> > the powerpc being able to run in either big or little endian mode. I
> > need to unpack some floats and doubles in a cross-platform way and yeah
> > I could do that in pure perl with some of the portable pack/unpack
> > commands and some byte twiddling, but that's going to be slow and so
> > I'll then end up maintaining two pieces of code, so I was thinking I
> > could compile perl to run in little-endian mode.
> >
> from `perldoc -f pack`:
>
> pack TEMPLATE,LIST
> [snip]
> n An unsigned short in "network" (big-endian) order.
> N An unsigned long in "network" (big-endian) order.
> v An unsigned short in "VAX" (little-endian) order.
> V An unsigned long in "VAX" (little-endian) order.
> (These 'shorts' and 'longs' are _exactly_ 16 bits and
> _exactly_ 32 bits, respectively.)
>
> maybe that will suffice? it will pack/unpack in the respective byte
> order on any platform, no byte twiddling needed.
There's a big note about how they decided not to tackle floats
and doubles:
* Real numbers (floats and doubles) are in the native
machine format only; due to the multiplicity of float‐
ing formats around, and the lack of a standard "net‐
work" representation, 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 representation is not part of
the IEEE spec). See also perlport.
Personally I think that's a cop out. The java people figured it
out (java.lang.float.floatToIntBits()).
On the other hand, what is it I hear people say when someone
complains about a lacking feature? Oh yeah.. "send code". Well, maybe I
will.
http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html
Austin
More information about the Pdx-pm-list
mailing list