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

math: Ldexp doesn't handle denormals correctly #23407

Closed
crvv opened this Issue Jan 11, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@crvv
Contributor

crvv commented Jan 11, 2018

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

1.9.2 and tip

Does this issue reproduce with the latest release?

Yes

What did you do?

https://play.golang.org/p/3OfmZgFcjRR

What did you expect to see?

math.Ldexp(1, -1075) = 0
math.Ldexp(1.000000000000001, -1075) = 5e-324
math.Ldexp(2, -1075) = 5e-324

What did you see instead?

math.Ldexp(1, -1075) = 0
math.Ldexp(1.000000000000001, -1075) = 0
math.Ldexp(2, -1075) = 5e-324

The result of ldexp_386.s is correct.
This issue is that the function ldexp written in Go doesn't handle denormals correctly.

@gopherbot

This comment has been minimized.

Show comment
Hide comment
@gopherbot

gopherbot Jan 11, 2018

Change https://golang.org/cl/87338 mentions this issue: math: fix Ldexp when result is below 5e-324

gopherbot commented Jan 11, 2018

Change https://golang.org/cl/87338 mentions this issue: math: fix Ldexp when result is below 5e-324

@odeke-em

This comment has been minimized.

Show comment
Hide comment
@odeke-em
Member

odeke-em commented Jan 11, 2018

@ALTree ALTree added the NeedsFix label Mar 11, 2018

@ALTree ALTree added this to the Go1.11 milestone Mar 11, 2018

@gopherbot gopherbot closed this in 4b265fb Mar 29, 2018

dmitshur added a commit to gopherjs/gopherjs that referenced this issue Jun 29, 2018

natives/math: Use Go implementation for extreme Ldexp inputs.
In Go 1.11, there has been an improvement made to Ldexp for some
extreme values. The previous Math.pow-using algorithm doesn't produce
correct results. Use the Go implementation of ldexp for those values.

Continue to use the current Math.pow approach for other inputs because
it's much faster:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	2000000000	         0.44 ns/op

Compared to using the Go implementation for all inputs, without the
Math.pow fast path:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	 5000000	       203 ns/op

Follows golang/go@4b265fb.
Updates golang/go#23407.

dmitshur added a commit to gopherjs/gopherjs that referenced this issue Jun 29, 2018

natives/math: Use Go implementation for extreme Ldexp inputs.
In Go 1.11, there has been an improvement made to Ldexp for some
extreme values. The previous Math.pow-using algorithm doesn't produce
correct results. Use the Go implementation of ldexp for those values.

Continue to use the current Math.pow approach for other inputs because
it's much faster:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	2000000000	         0.44 ns/op

Compared to using the Go implementation for all inputs, without the
Math.pow fast path:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	 5000000	       203 ns/op

Follows golang/go@4b265fb.
Updates golang/go#23407.

dmitshur added a commit to gopherjs/gopherjs that referenced this issue Jun 29, 2018

natives/math: Use Go implementation for extreme Ldexp inputs.
In Go 1.11, there has been an improvement made to Ldexp for some
extreme values. The previous Math.pow-using algorithm doesn't produce
correct results. Use the Go implementation of ldexp for those values.

Continue to use the current Math.pow approach for other inputs because
it's much faster:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	2000000000	         0.44 ns/op

Compared to using the Go implementation for all inputs, without the
Math.pow fast path:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	 5000000	       203 ns/op

Follows golang/go@4b265fb.
Updates golang/go#23407.

dmitshur added a commit to gopherjs/gopherjs that referenced this issue Aug 21, 2018

natives/math: Use Go implementation for extreme Ldexp inputs.
In Go 1.11, there has been an improvement made to Ldexp for some
extreme values. The previous Math.pow-using algorithm doesn't produce
correct results. Use the Go implementation of ldexp for those values.

Continue to use the current Math.pow approach for other inputs because
it's much faster:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	2000000000	         0.44 ns/op

Compared to using the Go implementation for all inputs, without the
Math.pow fast path:

	$ gopherjs test -v --run=none --bench=Ldexp math
	BenchmarkLdexp 	 5000000	       203 ns/op

Follows golang/go@4b265fb.
Updates golang/go#23407.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment