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

spec: inconsistent Behavior Dividing by 0.0 using Static vs Variable assignment #23524

Closed
TopherGopher opened this issue Jan 23, 2018 · 2 comments

Comments

@TopherGopher
Copy link

TopherGopher commented Jan 23, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/usterch/src/GO"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jf/ggd1wkrj6wn4zlqgt10xh66c5sxxm7/T/go-build295819013=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
Two links:
This compiles and runs successfully through: https://play.golang.org/p/SHkSuvdSoX5
This demonstrates the inconsistent behavior if I use a variable as the denominator: https://play.golang.org/p/_IfEAM4XsQu

What did you expect to see?

I should see the same behavior if I try to use a variable as when I use a constant.

What did you see instead?

Either both lines should fail, or neither should.

Related Issue

#10006

@ALTree
Copy link
Member

ALTree commented Jan 23, 2018

This behaviour is consistent with the spec. The spec forbids constant division by zero, but we have never generated compile-time errors for variables.

Regarding the run-time behaviour of your fist code snippet, note that

the result of a floating-point or complex division by zero is not specified beyond the IEEE-754 standard; whether a run-time panic occurs is implementation-specific.

So not even a crash at run-time is mandatory. Generating an IEEE-754 +Inf is allowed.

@ALTree ALTree changed the title Inconsistent Behavior Dividing by 0.0 using Static vs Variable assignment spec: inconsistent Behavior Dividing by 0.0 using Static vs Variable assignment Jan 23, 2018
@ianlancetaylor
Copy link
Contributor

This is working as documented. Closing.

If you want to discuss this, please use a forum. See https://golang.org/wiki/Questions. Thanks.

@golang golang locked and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants