Mail Archives: djgpp/1998/04/06/07:47:48
On Mon, 6 Apr 1998, Spider wrote:
> 2.390000        238.999987  
>                 ^^^^^^^^^^
> Isnīt this very poor????? I mean, if floats have a 6 decimals precision,
> one would expect an error less than exp(-6), right??
Wrong.  A float has 6 (actually, 6.5) *significant* digits.  That is, the 
3 digits before the decimal and 3 digits after it, in your case.  
Anything after that is more than a float can handle.  Use double if you 
have some *real* floating point math to do.
> no fp emulation (I use a i486DX2)!!! Is fp calculation that bad with
> djgpp?
It's not bad, it's what IEEE standard requires.
>  Doesn't it implement arithmetics with a (double) cast? 
You are mixing the arithmetics with the way fp variables are *stored*.  
x87 FPUs do their arithmetics in 10-byte (80-bit) quantities.  But when 
those values are stored, they lose the extra bits beyond what the 4-byte 
float can hold.  If you want all the precision you can get, declare the 
variables "long double" (that's 80-bit-wide).  But just "double" (64 bit) 
is usually enough.
- Raw text -