How well is FP defined across platforms?

Started by
6 comments, last by Jernej.L 18 years, 6 months ago
How preciesly the floating point arithmetic is defined (in IEEE 754) and how well different platforms (ie. x86/GCC,x86/VS,PPC/GCC) implement it? I'm writing a lossless audio codec and one part unfortunately relies on floating-point operations. It would be pain to rewrite this in fixed-point. So can I expect things such as rounding being consistent between platforms?
Advertisement
Quote:Original post by Winograd
How preciesly the floating point arithmetic is defined (in IEEE 754) and how well different platforms (ie. x86/GCC,x86/VS,PPC/GCC) implement it?
ALmost all modern platforms use IEEE floats (well, Alphas still support the old PDP format too). Some software implementations still provides custom formats though.
I wouldn't count on full support for those special condition values either (i.e. NaN, infinity).

Quote:Original post by Winograd
So can I expect things such as rounding being consistent between platforms?
Rounding is defined by C/C++ so that shouldn't be a problem.
In general you shouldn't have any problems unless you expect to be able to reproduce calculations bit-by-bit on different platforms.
http://grouper.ieee.org/groups/754/
is the first result on google and seems to be the official site, but it seems that a lot of the links are broken. Maybe you should look for an email address on the main IEEE site and ask them about it.

I'm fairly certain that the standard defines many rounding modes, and as far as I'm aware any of them can be the default mode. On most platforms, you can probably find a function to set the mode to your liking, but it'll definitely be on a per-compiler (and maybe on a per-architecture) basis

-Extrarius
Quote:Original post by doynax
Quote:Original post by Winograd
So can I expect things such as rounding being consistent between platforms?
Rounding is defined by C/C++ so that shouldn't be a problem.
In general you shouldn't have any problems unlles you expect to be able to reproduce calculations bit-by-bit on different platforms.


This is exactly what I'm expecting to. If the calculation involving floating point operations don't match bit by bit on different platforms then my codec won't be lossless. In fact, it will probably be unstable. A result of these operations will be sent to receiver as a one double.

This is what I meant when I asked how well is the fp-operations defined in 754. If two platforms implement the 754 and I still get different results on them, then the standard is not precise enough for me (hopefully this is not the case).

So I ask again, is there a way I can guarantee that the calculations will match bit-by-bit?
Quote:Original post by Anonymous Poster
http://grouper.ieee.org/groups/754/
is the first result on google and seems to be the official site, but it seems that a lot of the links are broken. Maybe you should look for an email address on the main IEEE site and ask them about it.

I'm fairly certain that the standard defines many rounding modes, and as far as I'm aware any of them can be the default mode. On most platforms, you can probably find a function to set the mode to your liking, but it'll definitely be on a per-compiler (and maybe on a per-architecture) basis

-Extrarius


I googled this myself before posting, I got some info there but the link to the standard was broken.
Quote:Original post by Winograd
Quote:Original post by doynax
Quote:Original post by Winograd
So can I expect things such as rounding being consistent between platforms?
Rounding is defined by C/C++ so that shouldn't be a problem.
In general you shouldn't have any problems unlles you expect to be able to reproduce calculations bit-by-bit on different platforms.

This is exactly what I'm expecting to. If the calculation involving floating point operations don't match bit by bit on different platforms then my codec won't be lossless. In fact, it will probably be unstable. A result of these operations will be sent to receiver as a one double.

I don't know for sure how strictly IEEE defines things however I know for a fact that you'll get different results in reality.
All it takes is for the compiler to optimize your code by changing your order of operations or optimize a constant division to a reciprocal multiplication. And even if you're working with single precision calculations the processor may still handle them in higher precision internally (the x86 and it's 80-bit internal FPU stack for instance).
Quote:Original post by Winograd
So I ask again, is there a way I can guarantee that the calculations will match bit-by-bit?
It may be possible to make it work on most platforms by carefully hand crafting the code in native assembler for each platform. You may be able to make it work on a limited scale in C, though you'll at least have to disable optimizations in the compiler.
But still, I suspect that you'll save yourself a lot of headaces by simply rewriting it with fixed point arithmetics.
Quote:Original post by doynax
I don't know for sure how strictly IEEE defines things however I know for a fact that you'll get different results in reality.


Thanks, I'll have to write it in fixed-point then...
On win32 platform the hardware floating point methods are controlled by setting the 8070CW control word, so we can assume that is possible on most platforms, ofcourse if your codec has problem only with rounding you can use your own rounding method that would work same on all platforms, it shouldn't be that much cpu overhead.

EDIT:
this should be helpful to you:
http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html

Projects: Top Down City: http://mathpudding.com/

This topic is closed to new replies.

Advertisement