Question:
Precision for old vs new C compilers?
2011-02-04 22:28:41 UTC
I have a program that calculates the distance of protein strands. It came from an old SGI computer and was compiled with cc, but now I'm trying to get it to work on a new Linux computer and compiling with gcc. Most of the output is the same on Linux, but there are some numbers (~5-10%) that deviate a little from the expected output.

Is it possible that the precision of doubles and floats is different between the two machines/compilers? If not precision, does anyone have other ideas that come to mind?
Three answers:
Techwing
2011-02-05 01:12:02 UTC
The precision of floating-point numbers hasn't changed in ages. By default, it's very poor, only about 6-7 digits on most platforms. Use doubles if you want more accuracy. If you need more than 15 digits or so, use decimal arithmetic packages (but they are very slow, so beware).



The actual precision depends on the hardware implementation of floating point and the compiler's use of that, so if you see a difference in precision, it's probably because you are running on different hardware, not because of any change in the compiler.
Light Cloud
2011-02-04 22:38:21 UTC
I'm not very familiar with C, but I know at least for other languages (like Java), some processors can use "extended precision" when dealing with floating point numbers. That is, instead of rounding to 32-bit floats or 64-bit doubles, they save intermediate results in extended precision, and only round back to 32 or 64-bits at the end of the entire calculation. These kinds of features might be processor-dependent (and perhaps also compiler-dependent, depending on if the compiler wants to use the feature or not).



I think I remember reading that, in -O3 optimization mode, gcc might actually attempt to rearrange floating point calculations to speed up computations. However, floating point calculations are not associative, so (a+b)+c is not necessarily equal to a+(b+c), so if gcc decides to do that (and its decision might be different across compiler versions and target platforms), floating point calculations might be different...
2016-10-06 03:13:45 UTC
I extremely have all my abode windows 98SE programming utility (all six courses) stored on a CD, so it somewhat relies upon on you no be counted if to maintain it or no longer. it could have fee to 3 one else who can no longer arise with the money for extra recent pcs. I even have all my abode windows from 3.11 Workgroups all the way as much as abode windows Vista stored on a DVD.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...