0

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
}
Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
JISHY
  • 1
  • 2
    `atan2(y,x)` where `y` (`3.4e14`) is MUCH larger than `x` (`9.0e-9`) by orders of magnitude is, indeed, ~90 degrees. So it's giving you the right answer. – lurker Sep 04 '13 at 17:36

2 Answers2

1

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).

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
0

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

ccook
  • 5,869
  • 6
  • 56
  • 81