Hi gophers,
There are at least three issues about the accuracy of our math package:
#8909 about Hypot, #9545 about Asinh and #9536 about Log.
I've made some investigation into the last issue about math.Log.
The reporter claimed that our math.Log is wrong for one particular input,
however, our result is still within 1ulp of the actual value.
The problem is just that our result is not the closest representable float64
value of the actual value. (i.e. our error is less than 1ulp as documented
The question is, to what degree of accuracy do we want for our math
package? Is 1ulp enough? Or do we need 0.5ulp, or guarantee the closest
representable value?
As an example, I've tested popular open source implementation of log on
float64 in libm. Most libraries (*BSD, newlib) are based on Sun's fdlibm, as
our code, and that only guarantees <1ulp error.
Glibc uses "IBM Accurate Mathematical Library", see
and uses multiple precision in the last reduction step to guarantee the "correct
rounded (to nearest) value of log(x)"
The only other piece code that computes the correct result for log is based
table, but no multiple precision floats.
(All the code except the glibc version is in:
so the question is:
1. are we content with <1ulp accuracy for our math package? If this is the
case, we can close all three issues with working as we've intended.
2. if not, are we willing to use multiple precision floats or 2KB lookup table
to make sure our math.Log always return the most correct answer?
Thanks.