This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: when is a double float nearest infinity ?
- From: Christian Bruel <chrbr at free dot fr>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 20 Jan 2007 13:07:07 +0100
- Subject: Re: when is a double float nearest infinity ?
I found the answer to my second question : I just needed to include
<fenv.h>. Attached a fixed version of the example. But I'm still puzzled
by the first question (why mdmax+dmax) gives infinity ?
attached a modified version of the test program, compiled with
gcc testinf.c -pedantic -ansi -mieee-fp -lm -Wall -O2
I also tried to compile with -moft-soft to check the libgcc behavior but
that lead to undefined `__eqdf2' `__adddf3' references.
thanks for any help
Christian
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <fenv.h>
const double infd=(double)1.0/(double)0.0;
void testinf(double v)
{
if (v == infd)
puts("infinity");
else if (v == DBL_MAX)
puts("ok nearest");
else
puts("error?");
}
int
main()
{
volatile double max=DBL_MAX;
#if 0
fesetround (FE_UPWARD);
#endif
if (fegetround() == FE_TONEAREST)
puts ("rounding to nearest");
testinf(max+(double)1.0);
testinf(max+max);
return 0;
}