Go math包的结果无效

huangapple go评论81阅读模式
英文:

Go math package has invalid result

问题

我刚刚在我的电脑上运行了这段代码:

package main

import (
   "fmt"
   "math"
)

func main() {
   const ali = 4e20
   fmt.Println(math.Sin(ali))
}

并得到了以下结果:

1.3471173831553043e+258

为什么正弦函数的结果超过了1?

Python和其他一些语言的结果是正确的。

英文:

I just ran this code on my pc:

package main

import (
   "fmt"
   "math"
)

func main() {
   const ali = 4e20
   fmt.Println(math.Sin(ali))
}

and got this result:

1.3471173831553043e+258

Why Sin result goes more than 1?

Python and some other languages have correct result

答案1

得分: 2

似乎只是实现的问题,如果输入大于2**49,会导致问题。在这里找到了一个非常古老的问题链接

英文:

It seems like it's just an issue with the implementation, if the input is more than 2**49 it causes issues. Found a really old issue here

huangapple
  • 本文由 发表于 2017年7月31日 01:45:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/45402834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定