whats up with Java's Math class ?

Started by
3 comments, last by SiCrane 16 years, 3 months ago
hi, Has anyone ever noticed, if you use java's Math class that when, for example you want the sine of 180 it gives you 1.224646 etc... Now, correct me if i'm wrong, but shouldn't the sine of 180 be 0? Does anyone know of any algorithms, or good links, for trigonometric functions when you are dealing with degrees?
Advertisement
As the documentation states, the angle you pass to sin(), cos() etc. is in radians, not degrees. Conviniently it also provides toRadians() if you prefer to work in degrees for some reason.
yeh, try using Math.sin(Math.toRadians(180)) and it gives you 1.224646...
sorry, i never saw that it was to the power -16. but should it not exactly be 0.
What Every Computer Scientist Should Know About Floating-Point Arithmetic

This topic is closed to new replies.

Advertisement