views:

133

answers:

2

Is it OK to send over network double floating point values (adjusted for correct byte order of course) and using them interchangeably on different cpu architectures, specifically i386, mips (couple of different cores), powerpc (e300, e500). No extremely old hardware.

Using gcc 4.2.1 as compiler with -Os for all architectures.

Supposedly it is IEEE-754 standard everywhere (is it?), yet as wikipedia says:

The IEEE 754-1985 allowed many variations in implementations (such as the encoding of some values and the detection of certain exceptions). IEEE 754-2008 has tightened up many of these, but a few variations still remain (especially for binary formats).

I have not intended to pass around NaNs or other special stuff, just valid decimal numbers.

+1  A: 

You're essentially asking "Can I transfer binary data between systems seamlessly". The answer would be Yes, as long as the two systems agree to the same format. If you know which CPU's your expecting, then check their IEEE standards complience and you should be in business.

Dead account
To check that is exactly what I want to avoid doing myself... :)
the dude
PowerPC will be IEEE complient, but it is Motorolla Byte ordering, where as the x86 is IEEE complient but Intel Byte ordering.
NoMoreZealots
+1  A: 

If you want to send representations of normalized numbers, you're totally safe on any modern architecture. In case of any doubt, check the architecture manual. For denormalized numbers you would have to check.

Of course you have to be able to dissamble into bytes and reassemble at the other end, using correct byte order, but it sounds like you know how to do that.

As noted, you can't expected different CPUs to implement every single part of the standard identically, but that's not necessary.

Conversion from IEEE floating point to ASCII is fraught with error; there were good papers in the 1990s by Guy Steele and Will Clinger. There was a later followup on doing it faster by Burger and Dybvig.

Norman Ramsey
Just checked the source of SQLite, which claims "cross platform database file" - it cares only about byte-order for its REAL datatype which essentially is a double. Sounds like I am safe to go. Thanks
the dude