stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: [PATCH] LDBL_MIN, LDBL_MAX incorrectly in overridden in floa t.h for INTEL C++ 8.1 on SLES9
Date Tue, 02 Aug 2005 03:12:51 GMT
Nick Gunn wrote:
> Is there a simple way to make a test for this?
> 
> A simple way to test for it is to make a simple program that sets a
> value to both sets of MIN/MAX and compile it so that any warning is an
> error.  However, I don't think that its simple to implement that to work
> on all platforms from within the build/test mechanism.

There is a semi-portable way to test it: the compiler complained about
LDBL_MIN causing a floating point underflow. The only values smaller
than LDBL_MIN that could cause an underflow are denormalized numbers.
The C99 macro isnormal() returns a nonzero value if and only if its
argument has a normal value (i.e., is neither zero, subnormal, infinite,
nor NaN). Here's the test case (compiled with Intel C 8.1 on IA64):

$ cat t.c && icc -c99 t.c && ./a.out
#include <assert.h>
#include <float.h>
#include <math.h>
#include <stdio.h>

long double foo (long double);

int main ()
{
     const long double x = 3.3621031431120935e-4932L;
     const long double y = LDBL_MIN;

     printf ("isnormal (%.*Lg) = %d\n"
             "isnormal (%.*Lg) = %d\n",
             LDBL_DIG, x, isnormal (x),
             LDBL_DIG, y, isnormal (y));

     assert (!isnormal (x));
     assert (isnormal (y));
}
t.c(10): warning #239: floating point underflow
       const long double x = 3.3621031431120935e-4932L;
                           ^

isnormal (3.3621031431120935e-4932) = 0
isnormal (3.36210314311209351e-4932) = 1

Mime
View raw message