作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试在 golang 中使用数学 API 中的 cos 函数,但由于某种原因,该函数返回了一个不正确的值。这个问题有已知的解决方案吗?
代码:
fmt.Println("cos(pi/2):", math.Cos(math.Pi / 2))
fmt.Println("sen(pi/2):", math.Sin(math.Pi / 2))
输出:
余弦(圆周率/2):6.123233995736757e-17
森(pi/2): 1
最佳答案
您看到的只是轻微的浮点误差。它正确地返回“几乎为零”。
参见:What Every Computer Scientist Should Know About Floating-Point Arithmetic .
关于function - golang中固定cos数学函数有没有解决办法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35516647/
我是一名优秀的程序员,十分优秀!