Ø "multiply first, then divide."
While often the right method, I don’t think that it always is. Consider:
- Integer: It is as long as the product doesn’t overflow (before the
divide).
- Floating: I’m inclined to think that combining numbers of the same
magnitude first might be a better approach.
John
John Souvestre - New Orleans LA
From: [email protected] [mailto:[email protected]] On
Behalf Of Michael Jones
Sent: 2017 August 18, Fri 11:50
To: golang-nuts
Subject: [go-nuts] multiply and divide
Here is a minor musing from something that came up yesterday.
Sometimes we see a real number expression as simple as...
x*y/z
...and knowing from basic algebra that...
(x*y)/z == x*(y/z)
...we might not expect much difference between the two in our code. Alas,
computer floating point does not involve real numbers, rather it uses an
approximation of them. If you will copy https://play.golang.org/p/IlDxtvx7IY to
your computer, build and run it, (too much CPU for the playground) you'll find
that the order makes a difference. Or, you can just remember this phrase,
"multiply first, then divide."
--
Michael T. Jones
[email protected]
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.