Mail Archives: djgpp/1998/02/22/20:47:19
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. Is there a similar
> class or option under DJGPP that will eliminate these round off
> errors?
round off errors are a fact of life if you are using floating point
arithmetic. your best bet is not to use floating point arithmetic for
accounting software. note that this is _not_ at all a djgpp specific
problem. basic floating point. if you want to see another example, try
C:\TEMP>type fp.c
#include <stdio.h>
int main(void)
{
int i;
float g, data[3] = { 1, -10e9, 10e9};
for(g=0.0, i=0; i<3; i++)
g += data[i];
printf("%g\n",g);
for(g=0.0, i=0; i<3; i++)
g += data[2-i];
printf("%g\n",g);
return 0;
}
C:\TEMP>fp
0
1
-- Sinan
- Raw text -