Skip to content

cmd/compile: finite scaling of complex infinity gives complex NaN #38757

Closed

Description

@kortschak

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

$ go version
go version go1.14.2 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="on"
GOARCH="amd64"
GOBIN="/home/user/bin"
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/user/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
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-build634029336=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run the code at https://play.golang.org/p/0WqB9HZZFwA

What did you expect to see?

should be complex inf: (+Inf+Infi)

What did you see instead?

should be complex inf: (NaN+NaNi)

Activity

  1. changed the title [-]cmd/compile: finite scaling of complex infinity give complex NaN[/-] [+]cmd/compile: finite scaling of complex infinity gives complex NaN[/+] on Apr 30, 2020
  2. bmkessler commented on May 1, 2020

    @bmkessler
    Contributor

    This is working as intended. The issue is the untyped constant 42 is converted to a complex number with zero imaginary part and the multiplication between Inf and 0.0 is NaN.

    cmplx.Inf()*42 == complex(math.Inf(1), math.Inf(1)) * (42 + 0i)
    ... == (math.Inf(1)*42-math.Inf(1)*0) + (math.Inf(1)*0+math.Inf(1)*42) i
    ... == (math.Inf(1) - math.NaN()) + (math.NaN() + math.Inf()) i
    ... == math.Nan() +math.NaN() i

    To scale by a real number rather than multiply by a complex number with zero imaginary part you need to write this as:

    x := cmplx.Inf()
    x = complex(42 * real(x), 42 * imag(x))

    See #38780 for further discussion.

  3. kortschak commented on May 1, 2020

    @kortschak
    ContributorAuthor

    Yeah, OK. The spec is terse on this. As mentioned in the linked issue, perhaps that could be improved.

  4. locked and limited conversation to collaborators on May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions