# [erlang-questions] sine and cosine with degree angles

Dmitry Belyaev <>
Thu Aug 26 14:16:05 CEST 2010

```Shame on me, wrong guards.

Hope, this one is better:
cos(0) -> 1;
cos(90) -> 0;
cos(180) -> -1;
cod(270) -> 0;
cos(Deg) when Deg < 0 -> cos(-Deg);
cos(Deg) when Deg >= 360 -> cos(Deg rem 360);
cos(Deg) -> math:cos(90 * math:pi() / 180).

Dmitry Belyaev

On 08/26/2010 04:09 PM, Dmitry Belyaev wrote:
>
> I just wanted to show that the problem is not with degrees but with
> real numbers.
> However, you can make your own sin/cos for _integer_ degrees:
>
> cos(0) -> 1;
> cos(90) -> 0;
> cos(-90) -> 0;
> cos(180) -> -1;
> cos(-180) -> -1;
> cos(Deg) when Deg >= 180 orelse Deg <= -180 -> cos(Deg rem 360);
> cos(Deg) -> math:cos(90 * math:pi() / 180).
>
> Dmitry Belyaev
>
>
> On 08/26/2010 03:57 PM, Roberto Ostinelli wrote:
>> 2010/8/26 Dmitry Belyaev<>:
>>> Suddenly
>>> 1>  math:sin(math:pi()).
>>> 1.2246063538223773e-16
>>>
>>> It's floating point, it's always not completely accurate.
>>>
>>> Check for epsilon range:
>>> -define(EPS, 1.0e-10).
>>>   if -?EPS<  Value andalso Value<  ?EPS ->  0; _ ->  Value end.
>>>
>>> Dmitry Belyaev
>> i know it's about approximations. this is why i was asking if i'm
>> missing an erlang function which takes degrees instead of radiants as
>> input.
>>
>> thank you for your suggestion, i will use the EPS.
>>
>> cheers :)
>>
>> r.
>>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>
```