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

gollvm/gofrontend: complex division produces wrong results. #52808

Open
xqq0629 opened this issue May 10, 2022 · 8 comments
Open

gollvm/gofrontend: complex division produces wrong results. #52808

xqq0629 opened this issue May 10, 2022 · 8 comments
Assignees
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@xqq0629
Copy link

xqq0629 commented May 10, 2022

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

$ go version

gollvm

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
Debian

Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz (Cascade Lake)

What did you do?

error case:

package main

import (
    "fmt"
    "math"
)

var (
    nan     = math.NaN()
    inf     = math.Inf(1)
    zero    = 0.0
)

func main() {
    var val complex128 = complex(zero, zero)
    var val1 complex128 = complex(nan, inf)

    res1 := val / val1
    fmt.Println(res1)
}

What did you expect to see?

(0+0i)
According to ISO/IEC 9899:1999 (E), (0+0i) / (NaN+Infi) = (0+0i)

What did you see instead?

(NaN+NaNi)

@randall77
Copy link
Contributor

The Go spec doesn't claim to follow ISO/IEC 9899:1999, so this may not be a bug.
That said, gc does produce (0+0i), and intentionally.

@heschi heschi added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 10, 2022
@heschi heschi added this to the Unreleased milestone May 10, 2022
@heschi
Copy link
Contributor

heschi commented May 10, 2022

cc @thanm

@thanm thanm self-assigned this May 10, 2022
@thanm
Copy link
Contributor

thanm commented May 10, 2022

I'll take a look.

@ianlancetaylor
Copy link
Contributor

gccgo also prints (0+0i).

@ianlancetaylor ianlancetaylor modified the milestones: Unreleased, gollvm May 10, 2022
@tsqua
Copy link

tsqua commented May 11, 2022

The Go spec doesn't claim to follow ISO/IEC 9899:1999, so this may not be a bug. That said, gc does produce (0+0i), and intentionally.

Currently, there is a running error in gonum testing. (https://github.com/gonum/gonum/tree/master/lapack/gonum)

@tsqua
Copy link

tsqua commented May 12, 2022

I'll take a look.

How about moving the implementation of complex128div function to runtime?
Then we can call runtime.complex128div when encounting complex division case.

@thanm
Copy link
Contributor

thanm commented May 12, 2022

How about moving the implementation of complex128div function to runtime?

That would be once way to do it.

@ianlancetaylor
Copy link
Contributor

As a historical note libgo used to have its own implementation of complex division (https://go.googlesource.com/gofrontend/+/6b01f8cdc11d86bd98165c91d6ae101bcf6b9e1a/libgo/runtime/go-cdiv.c). I removed it because because at least with gccgo it was no longer needed. But it didn't quite match the discussion on #14644, and removing it did match where that discussion wound up with the gc compiler. So I removed it (https://go.dev/cl/274213).

(I'm a bit surprised that GoLLVM doesn't just do what C99 expects by default.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants