-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: const eval should be exact independent of (mathematically equivalent) expression form (-G=3 option only) #43908
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
Comments
Change https://golang.org/cl/286552 mentions this issue: |
Change https://golang.org/cl/286572 mentions this issue: |
…, not floats Floating-point constants are represented as rational numbers when possible (i.e., when numerators and denominators are not too large). If we convert to floats when not necessary, we risk losing precision. This is the minimal fix for the specific issue, but it's too aggressive: If the numbers are too large, we still want to convert to floats. Will address in a separate CL that also does a few related cleanups. Fixes #43908. Change-Id: Id575e34fa18361a347c43701cfb4dd7221997f66 Reviewed-on: https://go-review.googlesource.com/c/go/+/286552 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
FYI, gccgo prints the same value twice, but it doesn't print
|
The test case is such that it should pass as long as both values are identical (which they are expected to be). The compiler now uses exact computations for "small-ish" rational numbers; and only switches to floats when using rational numbers would be too expensive. Presumably the difference between (the old) values 1.4916681462400413e-154 and 1.727233711018889e-77 stems from |
It is certainly true that gccgo currently uses a floating point precision of 256 bits. |
This has been fixed in the |
…ore consistently go/constant represents a Float constant either as a rational number (if numerator and denominator are small enough), or, as a "catch-all", as a arbitrary-precision floating-point number. This CL cleans up some of these transitions by factoring out more of the decision logic and documents the rationale between the state transitions better. This CL also simplifies some unrelated code that was overly complex. Updates #43908. Change-Id: Iccdd2d6b7fb7ed13d68ed5e6d992d1bc56a065bb Reviewed-on: https://go-review.googlesource.com/c/go/+/286572 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Factored out from #43891 :
should print the same value (0) for both
ulp1
andulp2
, but currently reports:This happens because
go/constant.ToFloat
doesn't convert to a rational number when it could, and then we lose mathematical precision.Note this only happens with when using the -G=3 option (new type checker).
The text was updated successfully, but these errors were encountered: