]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: add test for passing float32 signaling NaNs
authorKeith Randall <khr@golang.org>
Tue, 7 Sep 2021 22:13:51 +0000 (15:13 -0700)
committerKeith Randall <khr@golang.org>
Tue, 7 Sep 2021 23:10:23 +0000 (23:10 +0000)
Update #40724

Change-Id: I110cdb7c4a2c5db6b85ca951143430555261abf3
Reviewed-on: https://go-review.googlesource.com/c/go/+/348017
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/reflect/abi_test.go
src/reflect/all_test.go

index 2b247d1d7986ff4a72156882b23c51b1f3d5e0bb..873febbad2da5b3471decb08618385726d371404 100644 (file)
@@ -9,6 +9,7 @@ package reflect_test
 
 import (
        "internal/abi"
+       "math"
        "math/rand"
        "reflect"
        "runtime"
@@ -962,3 +963,27 @@ func genValue(t *testing.T, typ reflect.Type, r *rand.Rand) reflect.Value {
        }
        return v
 }
+
+func TestSignalingNaNArgument(t *testing.T) {
+       v := reflect.ValueOf(func(x float32) {
+               // make sure x is a signaling NaN.
+               u := math.Float32bits(x)
+               if u != snan {
+                       t.Fatalf("signaling NaN not correct: %x\n", u)
+               }
+       })
+       v.Call([]reflect.Value{reflect.ValueOf(math.Float32frombits(snan))})
+}
+
+func TestSignalingNaNReturn(t *testing.T) {
+       v := reflect.ValueOf(func() float32 {
+               return math.Float32frombits(snan)
+       })
+       var x float32
+       reflect.ValueOf(&x).Elem().Set(v.Call(nil)[0])
+       // make sure x is a signaling NaN.
+       u := math.Float32bits(x)
+       if u != snan {
+               t.Fatalf("signaling NaN not correct: %x\n", u)
+       }
+}
index 01ce8b0c43cd6f2c7b13a6fdf285ccbae27a4488..eb3ddcb3e4b935eb22d7b40a84e157dc80ea1508 100644 (file)
@@ -4428,8 +4428,9 @@ func TestConvertPanic(t *testing.T) {
 
 var gFloat32 float32
 
+const snan uint32 = 0x7f800001
+
 func TestConvertNaNs(t *testing.T) {
-       const snan uint32 = 0x7f800001
        type myFloat32 float32
        x := V(myFloat32(math.Float32frombits(snan)))
        y := x.Convert(TypeOf(float32(0)))