cos returns wrong values?

前端 未结 3 765
一整个雨季
一整个雨季 2020-12-07 04:13

I have a strange problem with the standard cos function of cmath/math.h. Apparently under some circumstances it returns a wrong or simply undefined value.

#i         


        
相关标签:
3条回答
  • 2020-12-07 04:40

    cos expects radians, you are giving it degrees. Multiply your input value by 3.14159/180, and you will get the right answer.

    0 讨论(0)
  • 2020-12-07 04:47

    cos(PI/2) = 0, not 1.

    0 讨论(0)
  • 2020-12-07 04:48

    I don't know if you're passing radian or degrees... But your value of foo is near PI/2. So you get cos(foo) = 0 and sin(foo) = 1 (what you expected?)

    0 讨论(0)
提交回复
热议问题