sine and cosine with degree angles

Roberto Ostinelli <>
Thu Aug 26 13:03:33 CEST 2010


dear list,

sorry if this does sound stupid but i need to compute sine and cosine
of angles expressed in degrees.

the math:sin/1 and math:cos/1 functions compute respectively the sine
and cosine of radiant angles, which can be converted to degrees simply
like this:

radians = degrees * π / 180

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).
1.0
2> math:sin(0 * math:pi() / 180).
0.0
3> math:cos(90 * math:pi() / 180).
6.123233995736766e-17
4> math:cos(0 * math:pi() / 180).
1.0

any suggestions on how to proceed? am i missing some erlang functions on this?

thank you,

r.


More information about the erlang-questions mailing list