ARM Technical Support Knowledge Articles

ERRORS IN DOUBLE ARITHMETIC

Applies to: C251 C Compiler

Answer


Information in this article applies to:


SYMPTOMS

The 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
}

CAUSE

The 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.

RESOLUTION

This problem is resolved in C251 Compiler V3.51 and available in C251 V3.53a.

SEE ALSO

ATTACHED FILES

Request the files attached to this knowledgebase article.

Article last edited on: 2005-05-20 08:12:36

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential