Subject: None
To: None <tech-net@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-net
Date: 08/07/2002 17:58:41
> I am having a doubt whether on sending between little endian and big
> endian machines floats have also to be converted like int (ntohl) or
> they are not to be converted.

Neither.  It's not that simple.

In particular, not all machines use the same floating-point format.
IEEE floats are very common these days, but there are others; the VAX
is the canonical example, and if the PDP-10 port gets off the ground, I
imagine it won't be using IEEE floats either.  You can't convert
between IEEE and VAX floats as simply as flipping bytes; you can do a
mostly decent job for most "ordinary" (non-infinite, non-NaN,
non-reserved-operand, within the ranges of both formats, etc) values by
juggling bits, and depending on how much you care about the low handful
of bits of the mantissa, and about the values each format has that the
other doesn't quite have (infinities, reserved operands, etc), that may
be good enough for you.

And that's just _one_ non-IEEE floating point format.  Even within
IEEE, as others have mentioned, it is not always as simple as one
endianness or the other.  (Indeed, historically, even integers aren't;
I think there was a machine that stored 32-bit values as two 16-bit
values, most-significant half first, but each of those 16-bit values
was stored least-significant byte first - 0x12345678 became 0x34 0x12
0x78 0x56.  I think it was not something NetBSD cares about, and you're
unlikely to run into anything like it today for integers.)

In general, you want to avoid throwing raw floats around between
heterogenous machines if you can manage it.  Why do you think you want
to?  I might be able to offer more helpful advice if I knew that.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B