diff options
author | Nia Weiss <[email protected]> | 2021-01-15 10:48:07 -0500 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-01-16 19:12:36 +0100 |
commit | a867b56e5f9e6778f48a33d75b6543b0ca92dcc1 (patch) | |
tree | c7e22400297b7acf9032d5c38dd57cfceac265d2 /testdata/float.go | |
parent | f159429152e90c7c821b96a05e18eef8b1213401 (diff) | |
download | tinygo-a867b56e5f9e6778f48a33d75b6543b0ca92dcc1.tar.gz tinygo-a867b56e5f9e6778f48a33d75b6543b0ca92dcc1.zip |
compiler: saturate float-to-int conversions
This works around some UB in LLVM, where an out-of-bounds conversion would produce a poison value.
The selected behavior is saturating, except that NaN is mapped to the minimum value.
Diffstat (limited to 'testdata/float.go')
-rw-r--r-- | testdata/float.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/testdata/float.go b/testdata/float.go index 8c33cf11b..6d2d1bca6 100644 --- a/testdata/float.go +++ b/testdata/float.go @@ -29,7 +29,12 @@ func main() { var f2 float32 = 5.7 var f3 float32 = -2.3 var f4 float32 = -11.8 - println(int32(f1), int32(f2), int32(f3), int32(f4)) + var f5 float32 = -1 + var f6 float32 = 256 + var f7 float32 = -129 + var f8 float32 = 0 + f8 /= 0 + println(int32(f1), int32(f2), int32(f3), int32(f4), uint8(f5), uint8(f6), int8(f7), int8(f6), uint8(f8), int8(f8)) // int -> float var i1 int32 = 53 |