0

i am using haversine formula in java programming (using eclipse). My problem is at the end of the equation where i get an error (atan is underlined) saying that "The method atan(double) is undefined for the type Math".

i dont know what is the problem. Does anyone have an idea?

    double angle = 45;
    double arctan = Math.atan(angle);
tsolias
  • 1
  • 2
  • 1
    Just a general math note: the argument of `atan` isn't an angle -- it _returns_ an angle. And it's in radians, not degrees. – trutheality Jul 24 '11 at 03:02

3 Answers3

2

Do you have any other Math class in the same package? Maybe you could try:

double angle = 45;
double arctan = java.lang.Math.atan(angle);
Robert Balent
  • 1,452
  • 11
  • 21
1

The only possible reason that I can think of for why this might happen is that there is a namespace conflict. That is to say that the compiler thinks the Math in your method is referencing some other Class called Math instead of java.lang.Math

In eclipse if you hover your mouse cursor over Math it will bring up a context window showing you what package it thinks Math belongs to. If it's not java.lang then that's your problem.

Dunes
  • 37,291
  • 7
  • 81
  • 97
  • it gives me all kind of choices like tan,abs,sin,cos..etc so it belongs in java.lang thank you but i dont think this is the problem – tsolias Jul 24 '11 at 04:08
1

Are you programming mobile application and using Java ME? In that case the Math library really doesn't contains atan function. So you have to calculate atan by yourself. This topic was discussed here and also here.

Community
  • 1
  • 1
Robert Balent
  • 1,452
  • 11
  • 21