• June 22nd, 2011, 05:46 AM
marksquall

A greeting of peace.

I am currently working on a simple program that uses trigonometric laws like sine laws. I first try to write this simple codes first:

Code :

```double angle = 60; System.out.println( Math.sin(Math.toDegrees(angle) );```

Then the output is: 0.7475(something)

I wonder why the output is 0.7475(something)? BUT, when I tried pressing sin 60 on my scientific calculator (in degrees mode as usual) the answer is 0.8660(something).

Then later, I tried to use toRadians() method in Math class:

Code :

```double angle = 60; System.out.println( Math.sin(Math.toRadians(angle) );```

Then that is the time I got the 0.8660 (something) answer.

I am just a little confused. My scientific calculator is in degrees mode, that is why I am expecting the same result if I will use the toDegrees() method, but why it did not?

Please enlighten me. Did I miss something?

Respectfully Yours,

MarkSquall

• June 22nd, 2011, 07:41 AM
ivy
Hi,

for Math.sin(doulbe a), a is an angle, in radians (pls refer to in API document), that's why sin(Math.toRadians(angle)) works.
• June 22nd, 2011, 07:44 AM
ivy
one more thing, following words are from API document, FYI.
about toDegrees, "The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0. "
• June 23rd, 2011, 01:28 AM
marksquall