[erlang-questions] sine and cosine with degree angles
Fri Aug 27 05:38:43 CEST 2010
On Aug 26, 2010, at 11:03 PM, Roberto Ostinelli wrote:
> however, due to approximations there seem to be an error in the
> computation of the cosine of 90° [which should be 0]:
> 1> math:sin(90 * math:pi() / 180).
> 2> math:sin(0 * math:pi() / 180).
> 3> math:cos(90 * math:pi() / 180).
> 4> math:cos(0 * math:pi() / 180).
As a matter of fact cos(90) looks about as good as it can
get. You can't get *precisely* close to pi/2; the closest
you can get is pi/2 +/- epsilon, and the cosine of that
will be -/+ epsilon.
Now Ada lets you write
cos(90, cycle => 360)
and Sun's math library lets you write
where cospi(x) = cos(pi * x) as if computed with an infinitely
precise pi. We would expect either of those to return an
With the traditional C interface, 6.123233995736766e-17 is as
close as you are going to get.
More information about the erlang-questions