atan2 (y,x) when y & x are very small

385 views Asked by At

I tried atan2 in C with argument of about 10-14. It gives a wrong answer: around 90 instead of zero, e.g.:

void main()
{
    double a =3.4e-14;
    double b=9e-10;
    atan2(3.4e14,9.0e-9); // returns ~90 instead of zero or Not a number
}
2

There are 2 answers

0
ccook On

It looks like you are calling atan2 on 3.4*10^14, not 3.14*10^(-14)?

0
Alex Shesterov On

You've defined two variables a and b in your code, but then you are using constants as arguments to atan2.

The values of a and b are just ignored.

atan2(a, b); 

would return a value near zero, as you would expect.

Same for atan2(3.4e-14,9.0e-9) (note e-14, not e14).