Issue #387 pointed out that integer float data is printed incorrectly, such that it is not parsed correctly by the Go assembler. Specifically, integer values need the decimal point, otherwise they will be treated as integers. For example, 1 must be represented as `$(1.)` or `$(1.0)` to be parsed correctly. This PR fixes that problem and adds a regression test. The root of the problem was that the formatting verb `%#v` does not have the right behavior for integers. We fix it by deferring to custom `String()` function for the float operand types. Fixes #387 Closes #388
28 lines
490 B
Go
28 lines
490 B
Go
package issue387
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
//go:generate go run asm.go -out issue387.s -stubs stub.go
|
|
|
|
func TestFloat32(t *testing.T) {
|
|
for i := 0; i < 10; i++ {
|
|
got := Float32(i)
|
|
expect := float32(i)
|
|
if got != expect {
|
|
t.Fatalf("Float32(%d) = %#v; expect %#v", i, got, expect)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFloat64(t *testing.T) {
|
|
for i := 0; i < 10; i++ {
|
|
got := Float64(i)
|
|
expect := float64(i)
|
|
if got != expect {
|
|
t.Fatalf("Float64(%d) = %#v; expect %#v", i, got, expect)
|
|
}
|
|
}
|
|
}
|