R: Strange trig function behavior

后端 未结 5 1270
独厮守ぢ
独厮守ぢ 2021-01-19 05:48

As a Matlab user transitioning to R, I have ran across the problem of applying trigonometric functions to degrees. In Matlab there are trig functions for both radians and de

5条回答
  •  日久生厌
    2021-01-19 06:22

    This is floating point arithmetic:

    > all.equal(cosd(90), 0)
    [1] TRUE
    > all.equal(cosd(270), 0)
    [1] TRUE
    

    If that is what you meant by "does not work properly"?

    This is also a FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

提交回复
热议问题