runtime: use dedicated printfloat32

It can be unexpected that printing a float32 involves 64-bit floating
point routines, see for example:
https://github.com/tinygo-org/tinygo/issues/1415

This commit adds a dedicated printfloat32 instead just for printing
float32 values. It comes with a possible code size increase, but only if
both float32 and float64 values are printed. Therefore, this should be
an improvement in almost all cases.

I also tried using printfloat32 for everything (and casting a float64 to
float32 to print) but the printed values are slightly different,
breaking the testdata/math.go test for example.
This commit is contained in:
Ayke van Laethem
2020-09-27 14:26:09 +02:00
committed by Ron Evans
parent 67de8b490d
commit 431e51b8a0
3 changed files with 87 additions and 3 deletions
+3
View File
@@ -29,6 +29,9 @@ func main() {
// print float64
println(3.14)
// print float32
println(float32(3.14))
// print complex128
println(5 + 1.2345i)
+1
View File
@@ -16,6 +16,7 @@ a b c
123456789012
-123456789012
+3.140000e+000
+3.140000e+000
(+5.000000e+000+1.234500e+000i)
(0:nil)
map[2]