M
matt
Hi group,
I read the description of function atan2() as given by opengroup at:
http://www.opengroup.org/onlinepubs/009695399/functions/atan2.html
In particular, I found the following sentences:
1) "An application wishing to check for error situations should set
errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
occurred."
2) "These functions may fail if: The result underflows."
I tried to check for underflow errors by using this code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <fenv.h>
int
main(void)
{
double x = 10e-324,
y = 10e-324;
errno = 0;
feclearexcept(FE_ALL_EXCEPT);
printf("x = %f\n", x);
printf("y = %f\n", y);
printf("atan2(x,y) = %f\n", atan2(x,y));
if ((errno != 0) ||
(fetestexcept(FE_INVALID |
FE_DIVBYZERO |
FE_OVERFLOW |
FE_UNDERFLOW) != 0)) {
perror("mah");
exit(-1);
}
return(1);
}
but without any success:
$ gcc -Wall -O0 main.c -o exe -lm
$ ./exe
x = 0.000000
y = 0.000000
atan2(x,y) = 0.785398
$
Can you throw some light on this, and/or provide me with an working example?
Thank you in advance,
I read the description of function atan2() as given by opengroup at:
http://www.opengroup.org/onlinepubs/009695399/functions/atan2.html
In particular, I found the following sentences:
1) "An application wishing to check for error situations should set
errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
occurred."
2) "These functions may fail if: The result underflows."
I tried to check for underflow errors by using this code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <fenv.h>
int
main(void)
{
double x = 10e-324,
y = 10e-324;
errno = 0;
feclearexcept(FE_ALL_EXCEPT);
printf("x = %f\n", x);
printf("y = %f\n", y);
printf("atan2(x,y) = %f\n", atan2(x,y));
if ((errno != 0) ||
(fetestexcept(FE_INVALID |
FE_DIVBYZERO |
FE_OVERFLOW |
FE_UNDERFLOW) != 0)) {
perror("mah");
exit(-1);
}
return(1);
}
but without any success:
$ gcc -Wall -O0 main.c -o exe -lm
$ ./exe
x = 0.000000
y = 0.000000
atan2(x,y) = 0.785398
$
Can you throw some light on this, and/or provide me with an working example?
Thank you in advance,