* Re: small doubles, g++, glibc, and linux/alpha problems
1998-03-08 5:00 small doubles, g++, glibc, and linux/alpha problems C R Johnson
@ 1998-03-08 5:00 ` H.W. Stockman
1998-03-09 5:00 ` Michal Jaegermann
1 sibling, 0 replies; 3+ messages in thread
From: H.W. Stockman @ 1998-03-08 5:00 UTC (permalink / raw)
To: C R Johnson
C R Johnson wrote:
>
> g++ 2.7 and egcs 1.0.1 running on a linux-alpha-glibc
> system
> is not taking kindly to small double values - those funky
> near zero values that you know should be zero, but have
> stupid values
> like 2.38723e-314.
>
> The problem does not show itself on my linux-intel-glibc
> system.
>
> #include <iostream.h>
> #include <cmath>
>
> int main()
> {
> cerr << "hello" << endl;
>
> double u = 2.38723e-314;
>
> cerr << "u = " << u << " M_PI = " << M_PI << endl;
> cerr << "u * M_PI = " << u * M_PI << endl;
>
> return 0;
> }
>
> The results:
>
> on linux - alpha - glibc
> +++++++++++++++++++++++++++++++++++++
>
> [cliff@van cliff]$ g++ hello.c++ -g -o hello <-- using gcc
> 2.7.1
> [cliff@van cliff]$ ./hello
> hello
> u = Floating point exception (core dumped)
> [cliff@van cliff]$ eg++ hello.c++ -g -o hello <-- using
> egcs 1.0.1
> [cliff@van cliff]$ ./hello
> hello
> u = 2.38723e-314 M_PI = 3.14159
> u * M_PI = Floating point exception (core dumped)
>
> slightly different results, but both hosed.
>
> on linux - intel - glibc
> +++++++++++++++++++++++++
>
> [cliff@brother_brent cliff]$ eg++ hello.c++ -g -o hello
> [cliff@brother_brent cliff]$ hello
> hello
> u = 2.38723e-314 M_PI = 3.14159
> u * M_PI = 7.4997e-314
>
> No problem ( with either compiler ) .
>
> Can anybody explain this? Is it a known problem? Can it be
> fixed. Must I
> resort to float's?
On an x86, 2.38723e-314 is a valid representation as a denormal,
and can be loaded onto the processor as such. The alpha
does not handle denormals in the processor, and generates
an exception when they are encountered. You can't represent
2.38723e-314 as a normal IEEE double precision number.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: small doubles, g++, glibc, and linux/alpha problems
1998-03-08 5:00 small doubles, g++, glibc, and linux/alpha problems C R Johnson
1998-03-08 5:00 ` H.W. Stockman
@ 1998-03-09 5:00 ` Michal Jaegermann
1 sibling, 0 replies; 3+ messages in thread
From: Michal Jaegermann @ 1998-03-09 5:00 UTC (permalink / raw)
C R Johnson (iamcliff@ix.netcom.com) wrote:
: g++ 2.7 and egcs 1.0.1 running on a linux-alpha-glibc
: system
: is not taking kindly to small double values - those funky
: near zero values that you know should be zero, but have
: stupid values
: like 2.38723e-314.
If you are using denormalized values add -mieee flag to a compiler
or you will get an exception.
Saying that Richard Henderson fixed some kernel bugs in handling
denormalized numbers in a kernel. You will find a "backport"
to 2.0.3x series attached below:
Michal
--- linux-2.0.33/arch/alpha/math-emu/ieee-math.c~ Fri Apr 12 00:49:30 1996
+++ linux-2.0.33/arch/alpha/math-emu/ieee-math.c Thu Feb 12 17:39:04 1998
@@ -137,9 +137,8 @@
static inline void
mul64 (const unsigned long a, const unsigned long b, unsigned long c[2])
{
- asm ("mulq %2,%3,%0\n\t"
- "umulh %2,%3,%1"
- : "r="(c[0]), "r="(c[1]) : "r"(a), "r"(b));
+ c[0] = a * b;
+ asm ("umulh %1,%2,%0" : "=r"(c[1]) : "r"(a), "r"(b));
}
@@ -276,7 +275,7 @@
{
unsigned long res, sticky;
- if (!a->f[0] && !a->f[1]) {
+ if (!a->e && !a->f[0] && !a->f[1]) {
*b = (unsigned long) a->s << 63; /* return +/-0 */
return 0;
}
@@ -356,7 +355,7 @@
{
unsigned long res, sticky;
- if (!a->f[0] && !a->f[1]) {
+ if (!a->e && !a->f[0] && !a->f[1]) {
*b = (unsigned long) a->s << 63; /* return +/-0 */
return 0;
}
@@ -384,7 +383,7 @@
a->e = -0x3ff;
}
}
- if (a->e > 0x3ff) {
+ if (a->e >= 0x3ff) {
res = FPCR_OVF | FPCR_INE;
if (f & IEEE_TRAP_ENABLE_OVF) {
a->e -= 0x600; /* scale down result by 2^alpha */
@@ -1143,12 +1142,9 @@
return 0;
}
op_c.s = op_a.s ^ op_b.s;
- op_c.e = op_a.e + op_b.e;
+ op_c.e = op_a.e + op_b.e - 55;
mul64(op_a.f[0], op_b.f[0], op_c.f);
- normalize(&op_c);
- op_c.e -= 55; /* drop the 55 original bits. */
-
return round_s_ieee(f, &op_c, c);
}
@@ -1200,11 +1196,8 @@
return 0;
}
op_c.s = op_a.s ^ op_b.s;
- op_c.e = op_a.e + op_b.e;
+ op_c.e = op_a.e + op_b.e - 55;
mul64(op_a.f[0], op_b.f[0], op_c.f);
-
- normalize(&op_c);
- op_c.e -= 55; /* drop the 55 original bits. */
return round_t_ieee(f, &op_c, c);
}
^ permalink raw reply [flat|nested] 3+ messages in thread