diff options
| author | Robert Griesemer <gri@golang.org> | 2021-01-25 15:18:56 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2021-01-25 23:44:22 +0000 |
| commit | 3663a437a781f4e7ce242aa334af2f2ce71ecef9 (patch) | |
| tree | 5d889b1f5839aad2548dba673bcf818b6c386db9 /src | |
| parent | 3432d24bab848a4fbae182e7d4399aa34ff6e302 (diff) | |
| download | go-3663a437a781f4e7ce242aa334af2f2ce71ecef9.tar.xz | |
[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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/go/constant/value.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/go/constant/value.go b/src/go/constant/value.go index 223c363d9b..2ed6115d1b 100644 --- a/src/go/constant/value.go +++ b/src/go/constant/value.go @@ -871,9 +871,9 @@ func ToInt(x Value) Value { func ToFloat(x Value) Value { switch x := x.(type) { case int64Val: - return i64tof(x) + return i64tor(x) case intVal: - return itof(x) + return itor(x) case ratVal, floatVal: return x case complexVal: |
