Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.12.12 linux/amd64
Does this issue reproduce with the latest release?
Yes, same result with both go1.12.12 and go 1.13.5.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/home/user/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/user/go" GOPROXY="" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build193953141=/tmp/go-build -gno-record-gcc-switches"
What did you do?
- Create a
reflect.Value
object from float32 sNaN. - Use
Value.Float()
on float32 sNaN, but it unexpectedly returns float64 qNaN.
This is different behavior than casting float32 sNaN to a float64, which correctly returns float64 sNaN.
This bug is blocking fxamacker/cbor#91. See fxamacker/cbor#93 for more info. This bug may be related to #36399.
https://play.golang.org/p/T7orv6p_C6h
package main
import (
"fmt"
"math"
"reflect"
)
func main() {
// Create a float32 signalling Nan.
f32 := math.Float32frombits(0x7f800001)
// Create a reflect.Value object from f32.
v := reflect.ValueOf(f32)
// Get its underlying floating-point value as float64.
f64 := v.Float()
// Returned float64 value has quiet-bit on.
u64 := math.Float64bits(f64)
if (u64 & 0x8000000000000) != 0 {
fmt.Println("Want sNaN, got qNaN")
}
}
What did you expect to see?
Value.Float()
of float32 sNaN should return float64 sNaN.
This is expected because casting float32 sNaN to float64 returns sNaN.
What did you see instead?
Value.Float()
of float32 sNaN returns float64 qNaN instead.
This is different result from casting float32 sNaN to float64.