Skip to main content

Command Palette

Search for a command to run...

Order of operations

Published
•1 min read•View as Markdown

For scientific computing, scientific visualization, and computer graphics (areas I am familiar with) order of operations is important. Why? Well, if you need to exactly replicate some number, whether you're using float16, float32, or float64, the only way to do it is to have the operation done the same way.

If you have a function that returns:

return d[0] * d[1] + d[1]*d[2] + d[2] * d[0];

then multiplication rules you learned in elementary school says you can change it to:

return (d[0] + d[1]) * d[2] + d[0] * d[1];

This is done because there's one fewer multiplications. But, if you're expecting the exact same floating point values on return, you might not get that.

More from this blog

It needs to be written down

59 posts