]> Cypherpunks repositories - gostls13.git/commit
cmd/gc: fix float32 const conversion and printing of big float consts
authorRuss Cox <rsc@golang.org>
Tue, 20 May 2014 02:57:59 +0000 (22:57 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 20 May 2014 02:57:59 +0000 (22:57 -0400)
commit60be4a245049218e3d56ce8d49d22f2847ebec3f
tree0a9b85323423cbea76226e9082c33e3d11382099
parent661298358c4c84ffacbc266321227a9b6efc7a3b
cmd/gc: fix float32 const conversion and printing of big float consts

The float32 const conversion used to round to float64
and then use the hardware to round to float32.
Even though there was a range check before this
conversion, the double rounding introduced inaccuracy:
the round to float64 might round the value further away
from the float32 range, reaching a float64 value that
could not actually be rounded to float32. The hardware
appears to give us 0 in that case, but it is probably undefined.
Double rounding also meant that the wrong value might
be used for certain border cases.

Do the rounding the float32 ourselves, just as we already
did the rounding to float64. This makes the conversion
precise and also makes the conversion match the range check.

Finally, add some code to print very large (bigger than float64)
floating point constants in decimal floating point notation instead
of falling back to the precise but human-unreadable binary floating
point notation.

Fixes #8015.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/100580044
src/cmd/gc/const.c
src/cmd/gc/go.h
src/cmd/gc/mparith1.c
src/cmd/gc/mparith3.c
test/float_lit2.go [new file with mode: 0644]
test/float_lit3.go [new file with mode: 0644]