| |||||
Technical Support Support Resources
Product Information | C251: ERRORS IN DOUBLE ARITHMETICInformation in this article applies to:
SYMPTOMSThe following C251 program does not produce correct double precision results.
#pragma FLOAT64
double v1 = 4.0;
double v2 = 6.0;
double x1, x2;
void double_error (void) {
x1 = v1/v2; // result: 0.666666666666666666
x2 = x1 + x1 + x1; // wrong result: 1.0 should be 2.0
x2 = x1 * v2; // wrong result: 2.0 should be 4.0
}
CAUSEThe C251 Compiler V3.50 and earlier contains a potential problem in the run-time library which may cause this effect. It only occurs when the end result is exactly a power of 2 (i.e. 0.25. 0.5, 1.0, 2.0, 4.0, 8.0). It occurs while rounding-up the final result and causes the result to be off by a factor of 2. The problem does not exist when you use constants that are calculated at the compiler level by the constant folding optimization. RESOLUTIONThis problem is resolved in C251 Compiler V3.51 and available in C251 V3.53a. SEE ALSOLast Reviewed: Friday, May 20, 2005 | ||||
| |||||