This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: floating point precision on gcc-4 differs using variables orarrays
Eljay Love-Jensen wrote:
Hi Asfand,
#1: C does a lot of its calculations in double, or long double (depending on platform).
Since this is for a game, I only need as little precision as possible.
Probably only about 3-4 decimal places. But since the "whole number
part" of the numbers (I forget the offical term, forgive me) need to
be arbitrarily large, I need to use floats.
#2: Intermediate results are often in long double.
Didn't know that. That kind of undermines the use of floats for
maximum speed.
#3: Consider carefully if you should be using float, double, long double, integer or fixed point for your purposes. The floating point numbers are finite precision.
If you are concerned about twiddly floating point number differences (which, otherwise, are to be EXPECTED)....
See above. I'm not concerned about precision, I just need to know
such errors are usual.
#4: Use -msoft-float to avoid twitchy hardware differences. (I'm not sure if this is 100% IEEE 754 compliant; check the documentation.) This will affect performance adversely.
Also...
As I recall, in the old days (pre-GCC 4.0), for many operations you'd have to explicitly use SSE instructions. Still required the SSE flag to be explicitly given. Hence, I believe Brian Budge's comments are valid and shouldn't be discounted out of hand.
I thank him for his input, but I checked the assembler in gcc 3.4.3,
and SSE floating point was being used. It seems to be used more
efficiently in gcc-4-cvs, which is a good thing.
#5: GCC 4.x has not been released yet. Use with caveats.
I understand that - but the errors would have been far more off it it
had been a bug. I just needed confirmation that this sort of stuff
was expected - and it seems it is, so that's fine.
All the above is well and good, but please could someone answer the
following question? Is it easier for the compiler to work with
numbers as variables (float a, float b, etc.) or as arrays (float
data[4]) ? By easier, I mean is it easier for it to perform
optimisations.
Thanks,
Asfand Yar