math: math.Log does not handle subnormal floating point number on amd64 #56600
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?macOS and amd64
go env
OutputWhat did you do?
I tried
math.Log
on very small float64 (subnormal IEEE floating point number), it gives incorrect result. This only happens on amd64, whenmath/log_amd64.S
is used.Running the same go code on, for example, arm64 gives correct results. I found
math/log_amd64.S
doesn't normalize subnormal floating number, whereas the go implementation of math.log (which calls math.Frexp) does normalise the floating point number. Hence different arch gives different results.What did you expect to see?
The natural log for subnormal floating number should be correct. The equivalent c code gives correct result (python/java also gives the same results as c, although they possibly just call the c implementation):
What did you see instead?
go.dev/play link: https://go.dev/play/p/uksqrp1Zq0-
The text was updated successfully, but these errors were encountered: