[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ldexpl test fix
From: |
Bruno Haible |
Subject: |
ldexpl test fix |
Date: |
Sat, 5 Nov 2011 17:01:20 +0100 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
It's well-known that the "extended precision" (80-bit 'double') numbers
of the x86 processors cause trouble when there are rounding errors.
But they can also cause trouble when no rounding errors are involved.
When all involved numbers are powers of 2!
It can be observed in this program:
============================================
#include <math.h>
#include <stdio.h>
int main()
{
double x = ldexp (1.0, 1020);
double y = x * 32.0;
fprintf (stderr, "%d\n", y == x * 32.0);
return 0;
}
============================================
With the MSVC 9 compiler, this program prints 0.
The reason is that the "extended precision" numbers not only have a
larger precision (64 as opposed to 53 bits), but also a larger
exponent range (15 bits, compared to 11 bits). This means that
overflow (conversion of values > DBL_MAX to Infinity) is delayed.
Seen when the ldexpl test fails on MSVC 9:
test-ldexpl.c:97: assertion failed
FAIL: test-ldexpl.exe
Fixed as follows.
2011-11-05 Bruno Haible <address@hidden>
ldexpl tests: Avoid test failure on MSVC 9.
* tests/test-ldexpl.c (main): Use a temporary variable for the expected
value. Needed in order to enforce the conversion from a value greater
than LDBL_MAX to Infinity.
--- tests/test-ldexpl.c.orig Sat Nov 5 17:00:04 2011
+++ tests/test-ldexpl.c Sat Nov 5 16:49:50 2011
@@ -94,7 +94,12 @@
for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
{
y = ldexpl (x, 0); ASSERT (y == x);
- y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
+ {
+ volatile long double expected;
+ y = ldexpl (x, 5);
+ expected = x * 32.0L;
+ ASSERT (y == expected);
+ }
y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
}
for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
--
In memoriam Bernhard Lichtenberg
<http://en.wikipedia.org/wiki/Bernhard_Lichtenberg>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- ldexpl test fix,
Bruno Haible <=