1
0
mirror of https://github.com/golang/go synced 2024-11-11 23:50:22 -07:00

reflect: add test for passing float32 signaling NaNs

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>
This commit is contained in:
Keith Randall 2021-09-07 15:13:51 -07:00
parent b5e33a50fe
commit b606739be6
2 changed files with 27 additions and 1 deletions

View 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)
}
}

View 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)))