Math.cos() gives wrong result

z3on picture z3on · Oct 19, 2012 · Viewed 47.8k times · Source

According to Wolfram Mathematica: cos(50) = 0.6427876096865394;

But this code in Java:

    System.out.println(Math.cos(50));

gives 0.9649660284921133.

What is wrong with java.lang.Math?

Answer

Dan D. picture Dan D. · Oct 19, 2012

Math.cos() expects the parameter to be in radians. This will return the result you need:

Math.cos(Math.toRadians(50));