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: handle unicode minus in ParseFloat #36782

Closed
mashedkeyboard opened this issue Jan 26, 2020 · 3 comments
Closed

strconv: handle unicode minus in ParseFloat #36782

mashedkeyboard opened this issue Jan 26, 2020 · 3 comments
Labels
FeatureRequest FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@mashedkeyboard
Copy link

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

$ go version
go version go1.13.6 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/curtispf/.cache/go-build"
GOENV="/home/curtispf/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/curtispf/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build794045532=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Called strconv.ParseFloat with a negative number in a string denoted by the Unicode minus symbol, . See https://play.golang.org/p/NrryLknwcOz

What did you expect to see?

A Unicode mathematical minus should result in a negative number.

What did you see instead?

The call with a Unicode minus simply errors.

@ALTree
Copy link
Member

ALTree commented Jan 26, 2020

I don't think that was ever supposed to work. We can frame this as a feature request to be evaluated, I guess.

@ALTree ALTree changed the title strconv: ParseFloat doesn't handle the unicode minus correctly strconv: handle unicode minus in ParseFloat Jan 26, 2020
@ALTree ALTree added FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Jan 26, 2020
@ALTree ALTree added this to the Unplanned milestone Jan 26, 2020
@ianlancetaylor
Copy link
Contributor

strconv.ParseFloat is intended to accept the exact floating point syntax that the language accepts, as defined in https://golang.org/ref/spec#Floating-point_literals. There is no support for any sign characters other than + and -. That is as intended, so closing this issue.

If you want to make a proposal to change this, we need to consider more than just the single Unicode minus character. I think you are suggesting that we support U+2212 (−), but why shouldn't we also support U+2796 (➖), U+FE64 (﹣), U+FF0D (-)? And why stop at minus signs? What about U+1D7CE (𝟎), U+1D7D8 (𝟘), etc.?

@mashedkeyboard
Copy link
Author

but why shouldn't we also support U+2796 (heavy_minus_sign), U+FE64 (﹣), U+FF0D (-)?

Because those symbols are not mathematical operators according to Unicode. U+FF0D is in the punctuation category, as is ﹣ (which is actually U+FE63, not 64), and U+2796 is in the Other Symbol category. The minus sign is in the block of mathematical operators.

And why stop at minus signs? What about U+1D7CE (𝟎), U+1D7D8 (𝟘), etc.?

The block of Mathematical Alphanumeric Symbols, which both of those come from, are almost exclusively used for mathematical equations, which wouldn't be applicable to ParseFloat in the first instance. Indeed, the only item in the block of Mathematical Operators which I can see being directly applicable to parsing a simple float is the minus sign (http://www.fileformat.info/info/unicode/block/mathematical_operators/list.htm).

@golang golang locked and limited conversation to collaborators Jan 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants