Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strconv: document ParseFloat's special cases (nan, inf) #30990

Open
johnbalvin opened this Issue Mar 21, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@johnbalvin
Copy link
Contributor

johnbalvin commented Mar 21, 2019

What version of Go are you using (go version)?

go version go1.12 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\TATA\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\TATA\Documents\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\TATA\AppData\Local\Temp\go-build125692270=/tmp/go-build -gno-record-gcc-switches

What did you do?

Convert some string values to float

package main

package main

import (
	"fmt"
	"strconv"
	"log"
)

func main() {
	s, err := strconv.ParseFloat("nan", 32)
	if err != nil {
		log.Printf(" err: %s: ",err)
	}
	fmt.Printf("%T, %v\n", s, s)

}

What did you expect to see?

Error showing in the console because NaN is not a number

What did you see instead?

NaN

@randall77

This comment has been minimized.

Copy link
Contributor

randall77 commented Mar 21, 2019

This is intentional behavior. I think we just need to mention it in the docs.

@randall77 randall77 changed the title strconv.ParseFloat returns NaN when the input source is the string "NaN" strconv: document ParseFloat's special cases (nan, inf) Mar 21, 2019

@randall77 randall77 added this to the Go1.13 milestone Mar 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.