Subject: Re: HUGE_VAL - NAN
To: Patrick Welche <prlw1@newn.cam.ac.uk>
From: Richard Earnshaw <rearnsha@arm.com>
List: port-arm32
Date: 04/18/2000 13:43:03
OK. The problem is that __nanf is not correctly aligned, so that when
read as a double we get garbage. If you add the following to the top of
your program, then this overrides the libc version of __nanf and we get
the correct results.
const char __nanf[] __attribute__((aligned(2))) = { 0, 0, (char)0xc0, 0x7f
};
The other way to write it (of course) is
const unsigned __nanf[] = { 0x7fc00000 };
This should be send-pr'ed. A similar fix is also required for Infinity:
we have just been lucky there so far.
R.
>
> #include <math.h>
> #include <stdio.h>
>
> int main()
> {
> printf("+/-inifinity, EARLY:\n");
> printf(" HUGE_VAL: % g\n", HUGE_VAL);
> printf("-HUGE_VAL: % g\n",-HUGE_VAL);
>
> printf("invalid:\n");
> #ifdef NAN
> printf("NAN: %g, isnan(NAN): %i\n",NAN,isnan(NAN));
> #else
> printf("2min: %g\n",DBL_MIN+DBL_MIN);
> #endif
>
> return 0;
> }
>
>
> +/-inifinity, EARLY:
> HUGE_VAL: Inf
> -HUGE_VAL: -Inf
> invalid:
> NAN: 3.31756e-39, isnan(NAN): 0
>
>
> and from /sys/arch/arm32/include/math.h
>
> #define NAN (*(__const float *)(__const void *)__nanf)
>
> cf i386:
>
> +/-inifinity, EARLY:
> HUGE_VAL: Inf
> -HUGE_VAL: -Inf
> invalid:
> NAN: NaN, isnan(NAN): 1
>
>
> Cheers,
>
> Patrick