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
trivially replacing division with multiplication still sometimes useful #41657
Comments
(Side note: I'm not sure that's theoretically safe, because there could exist inputs for which the result isn't the same, but I've never actually found one of them.) |
... and someone just pointed out that this rule is already there for |
Actually, thinking about it more: I believe there exist values such that reciprocalExact(c) is false, but where there's no input float32 value for which multiplication by the reciprocal produces a different result from division by the original value. Hmm. (... no wait, there almost certainly aren't. yay for math.) |
Yes, I think this is unlikely to ever work. Closing
Produces
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
y
What operating system and processor architecture are you using (
go env
)?x86
What did you do?
divided by a constant
What did you expect to see?
multiplication by its reciprocal
What did you see instead?
cycles. so many cycles.
https://play.golang.org/p/vW3TLeBm4KP
On a laptop:
BenchmarkMul-8 127098 9497 ns/op
BenchmarkDiv-8 106873 11400 ns/op
That's a pretty huge speedup for such a trivial code change.
The text was updated successfully, but these errors were encountered: