New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
math/big: Float.Sqrt does not set accuracy #37915
Comments
Yeah
but I'm not sure it applies to cc @griesemer |
(small note: the Go equivalent of cmath's |
Another point, 0.1 + 0.2 = 0.3 is "Inexact" in go. r := big.NewFloat(0).Add(big.NewFloat(0.1), big.NewFloat(0.2))
log.Println(r.Acc())
// "Above" |
@mohanson that is correct. 0.1 and 0.2 and 0.3 are not exactly representable in IEEE-754. |
I see four ways this could be addressed:
Solution 1) is not a good idea. 4) might not be very expensive but I don't know if it is feasible. This leaves us with 2) or 3). We should start with 2) (easy), and then follow up with 3) if if turns out that the extra multiplication is an acceptable cost. Since we always care about speed, it probably isn't. For an application that needs to know whether the Sqrt was exact, it's always possible to do 3) separately. If this turns out to be important (which I doubt), one could even have a |
Change https://golang.org/cl/224497 mentions this issue: |
Document that the Float.Sqrt method does not set the receiver's Accuracy field. Updates #37915 Change-Id: Ief1dcac07eacc0ef02f86bfac9044501477bca1c Reviewed-on: https://go-review.googlesource.com/c/go/+/224497 Reviewed-by: Robert Griesemer <gri@golang.org>
The original issue was fixed by updating the documentation. Leaving this issue open as a reminder to investigate a better solution. No urgency. See also #37915 (comment). |
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
)?go env
OutputWhat did you do?
I was researching ieee 754, and when using go, I found that the
big.Float.Sqrt
function always output exact results. I calculate sqrt(pi) with go and cpp on one enviroment:Go
Cpp
What did you expect to see?
What did you see instead?
I don't think this is an accurate value, for
sqrt(pi) = 1.7724538498928541
in goThe text was updated successfully, but these errors were encountered: