math: Log1p may not be quite correct #29488
Labels
FrozenDueToAge
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?
Presumably; the file math/log1p hasn't changed in 2 years.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Use the math.Log1p function
What did you expect to see?
An error of less than 1 ULP, as the log1p.go file's "Accuracy:" comment states
What did you see instead?
Very large errors for a small set of inputs.
First of all, I would like to apologize for not creating a pull request - I don't really know how git works...
I have determined that the problem is in the file math/log1p.go. Lines 154 - 159 (as of this writing) are:
whereas they should be:
The comment at the top of the file states:
however the code only does the proper c/u step if k < 0 (that's when the input to logp1 is between -1 and -0.29ish). For inputs between (2^p)-1 and 2^p for p from 1 to 52, the variable c is not calculated correctly. The maximum absolute error I have found is 0.5.
The playground shows the result of this issue. The inputs listed are in order, yet the log1p of the middle one is 0.5 larger than the other two. The error is around 1%.
I have also found the file from FreeBSD that is mentioned in the log1p.go header. It contains the following C:
The line
c /= u
is run no matter the result of(k>0)
is, unlike the Go code.The text was updated successfully, but these errors were encountered: