Forums Register Login

problems with Math.tan

+Pie Number of slices to send: Send
The following code:

Gives the following output:

degrees = 72.0
tanDegrees = -0.26241737750193517


While my calculator returns something different:

3.077683537


What am I doing wrong in the Java source?
[ January 10, 2004: Message edited by: Kevin de Berk ]
+Pie Number of slices to send: Send
You're assuming that the tan funtion uses degrees. It doesn't - the API says it uses radians (pi=3.1419... radians equals 180 degrees). Most calculators have several possible modes - a "DRG" button toggles between degrees mode, radians mode, and grad mode (which has 100 grads in a 90 degree angle; seldom used). Your calculator is currently in degrees mode. Java's Math class doesn't have these modes; it always uses radians because that's the most mathematically natural mode to use. (Computations are actually simplest for the computer this way.) But you can use the toDegrees() and toRadians() methods to convert between radians and degrees.
+Pie Number of slices to send: Send
Oh..
Well, thanks mate
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2417 times.
Similar Threads
comparison methods
did you know that cos(90) != 0
how degrees can be converted to radians
How to calculate the angle of 2 points on a circle in clockwise direction
What operations produce NaN?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:39:10.