Mail Archives: djgpp/1999/09/29/22:57:24
At 10:37 29/09/99 +0200, Eli Zaretskii wrote:
>
>On Tue, 28 Sep 1999, nebo wrote:
>
>> Does DJGPP fix rounding errors with decimal places? I know
>> some compilers use BCD math to circumvent this problem, but
>> I found nothing of the sort in DJGPP.
>
>Please explain more about what you are asking. What rounding errors
>did you have in mind, and why do they need fixing with BCD?
>
>Floating-point computations in DJGPP run with 80-bit internal
>precision of the numerical co-processor, if that helps.
>
>
Try this small snippet in your machine:
#include <stdlib.h>
#include <stdio.h>
int
main(void)
{
int i;
float number = 0.0f;
for (i=0; i< 10000000; i++)
number += 0.001;
printf("Result is %5.2f\n", number);
return 0;
}
In _my_ equipment (a 233MMX Pentium running Win95), gcc 2.8.1:
bash$ gcc -o teste teste.c
bash$ ./teste
Result is 9780.20
This is a problem common to all programming languages, and has to do with
the representation of numbers in binary form. Nor 80 bit helps here. . .
Hope this clarifies.
This problem for certain application domains (e.g. when calculations about
money are being done) is more than a nuisance, this is the reason why the
BCD stuff was developed.
HTH
Cesar
- Raw text -