tan(pi/2) overflow
Edwin Helbert Aponte Angarita
helbert2a@gmail.com
Fri Apr 8 23:27:00 GMT 2011
Hello.
Though the GNU libc manual says:
"Mathematically, the tangent function has singularities at odd multiples
of pi/2. If the argument x is too close to one of these singularities,
tan will signal overflow."
the next code:
_________________________
#include <stdio.h>
#include <math.h>
#include <fenv.h>
int
main (void)
{
double val1;
int raised;
#if defined(FE_OVERFLOW)
feclearexcept (FE_ALL_EXCEPT);
val1 = tan (M_PI/2);
raised = fetestexcept (FE_OVERFLOW);
if (raised)
printf ("Overflow\n");
else
printf ("No overflow\n");
printf ("%G\n",val1);
#else
printf ("FE_OVERFLOW not defined\n");
printf ("%G\n",tan(M_PI/2));
#endif
return 0;
}
_________________________
compiled this way:
gcc -Wall -lm -g -o test-float.out test-float.c
is giving this output:
./test-float.out
No overflow
1.63312E+16
Even compiling this way:
gcc -ftrapv -fwrapv -fexceptions -Wall -lm -g -o test-float.out\
test-float.c
the output is the same.
So, anyone knows how can I get tan(pi/2) to raise the overflow
exception.
Thanks.
More information about the Gcc-help
mailing list