Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top