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

gccgo: math: Ldexp mishandles exp larger than 32-bit #21323

Closed
cherrymui opened this issue Aug 6, 2017 · 6 comments
Closed

gccgo: math: Ldexp mishandles exp larger than 32-bit #21323

cherrymui opened this issue Aug 6, 2017 · 6 comments
Milestone

Comments

@cherrymui
Copy link
Member

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

Go tip (~1.9), gccgo gccgo (GCC) 8.0.0 20170725 (experimental)

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

linux/amd64

What did you do?

package main

import (
        "fmt"
        "math"
)

var i int64 = 1<<32 + 1

func main() {
        fmt.Println(math.Ldexp(1.0, int(i)))
}

What did you expect to see?

With gc toolchain, the program above prints +Inf on linux/amd64. I believe this is the expected result.

What did you see instead?

With gccgo, the program above prints 2 on linux/amd64.

gccgo's math.Ldexp uses libc_ldexp, which is defined in C as double ldexp(double x, int exp). On linux/amd64, C's int is 32-bit whereas Go's int is 64-bit, causing this problem.

@ianlancetaylor

@gopherbot gopherbot added this to the Gccgo milestone Aug 6, 2017
@thanm
Copy link
Contributor

thanm commented Aug 8, 2017

Cherry, I can take a shot at fixing this if you don't already have a CL -- let me know.

@cherrymui
Copy link
Member Author

@thanm, thank you.
No, I don't have a CL.

@gopherbot
Copy link

Change https://golang.org/cl/54230 mentions this issue: math: additional tests for Ldexp

gopherbot pushed a commit that referenced this issue Aug 9, 2017
Add test cases to verify behavior for Ldexp with exponents outside the
range of Minint32/Maxint32, for a gccgo bug.

Test for issue #21323.

Change-Id: Iea67bc6fcfafdfddf515cf7075bdac59360c277a
Reviewed-on: https://go-review.googlesource.com/54230
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@thanm thanm self-assigned this Aug 9, 2017
@thanm
Copy link
Contributor

thanm commented Aug 9, 2017

Fix by https://go-review.googlesource.com/c/54250
No sure why, but gopherbot didn't auto-close.

@thanm thanm closed this as completed Aug 9, 2017
@ianlancetaylor
Copy link
Contributor

It didn't auto-close because it wasn't written as "#21323". Sorry I didn't catch that.

@thanm
Copy link
Contributor

thanm commented Aug 9, 2017

Ah ok, thanks. I'll try to remember.

@golang golang locked and limited conversation to collaborators Aug 9, 2018
@rsc rsc unassigned thanm Jun 23, 2022
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