]> Cypherpunks repositories - gostls13.git/commit
[dev.typeparams] go/constant: in ToFloat, convert to rational numbers, not floats
authorRobert Griesemer <gri@golang.org>
Mon, 25 Jan 2021 23:18:56 +0000 (15:18 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 25 Jan 2021 23:44:22 +0000 (23:44 +0000)
commit3663a437a781f4e7ce242aa334af2f2ce71ecef9
tree5d889b1f5839aad2548dba673bcf818b6c386db9
parent3432d24bab848a4fbae182e7d4399aa34ff6e302
[dev.typeparams] go/constant: in ToFloat, convert to rational numbers, 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>
src/go/constant/value.go
test/fixedbugs/issue43908.go [new file with mode: 0644]