Mail Archives: djgpp/1998/02/23/05:42:37
Alfredo J. Cole wrote:
>
> Compiling the following code with DJGPP gives the erroneous result
> (5551.20). The same code compiled with Borland's bcd class gives the
> correct result (5551.22). I am developing an accounting system with
> DJGPP and it requires that the results be exact.
Yes, it is because type 'float' contains only 20bit mantisse.
Somewhere in <float.h> (or <math.h>) you can see declaration
FLT_DIG - the precesion of float in decimal digits
For ieee compliant 32 bits float it will be only 6, so your is
quite predictible.
> Is there a similar
> class or option under DJGPP that will eliminate these round off
> errors?
Use 'double': it will be faster and increase precesion up to
15 decimal digits (DBL_DIG).
OR try to use fixed-point arythmetic - it will works like this:
int val = 555122;
printf("val = %d.%02d\n", val / 100, val % 100);
regards
tim.
- Raw text -