-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: math.SmallestNonzeroFloat64 is not sufficiently precise, leading to unexpected results #44058
Comments
i think it's a mistake, in golang compile, the math.SmallestNonzeroFloat64 / 2 will use big.Float to calculate multi-precision floating, and when transform to float64 the precision will loss, so the print will undefined. and your example use big.Rat, it's different |
math.SmallestNonzeroFloat64 / 2 is a special example will rounding to math.SmallestNonzeroFloat64, the logic is here。change the
|
Change https://golang.org/cl/288672 mentions this issue: |
|
Program to compute accurate values to 512 bits. |
Change https://golang.org/cl/315170 mentions this issue: |
Change https://golang.org/cl/315969 mentions this issue: |
Follow-up on https://golang.org/cl/315170. Updates #44057. Updates #44058. Change-Id: I0b071e8ee7a1c97aae2436945cc9583cde3b40b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/315969 Trust: Robert Griesemer <gri@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
The compiler constant expression
gets printed as
5e-324
(program), but the exact computation ofmath.SmallestNonzeroFloat64 / 2
usingmath/big
arithmetic followed by rounding results in0
(program).There's either an error with the rounding or constant arithmetic somewhere, or a mistake in my assumptions.
This affects a test case in
types2/testdata/const1.src
.The text was updated successfully, but these errors were encountered: