Link: Survey of [floating point] Rounding Implementations in Go

July 6, 2017

Matt Jibson's Survey of Rounding Implementations in Go (via) is sort of what it says, namely a survey of a bunch of floating point rounding implementations:

Rounding in Go is hard to do correctly. That is, given a float64, truncate the fractional part (anything right of the decimal point), and add one to the truncated value if the fractional part was >= 0.5. [...]

But it's a lot more than that, because the article then proceeds to demonstrate just how complicated floating point rounding really is (in any language), how non-obvious this complexity is, and how easy it is to get it wrong. It ends with a walk-through of what will be math.Round in Go 1.10, which is implemented not through floating point operations but through direct knowledge of how floating point values are implemented at the bit level.

Floating point is one of those things in programming that looks like it's reasonably simple but instead is a deep pit of potential complexity once you move beyond doing very simple things. I enjoy articles like this because they are both a good reminder of this and a peek behind the curtain.

Written on 06 July 2017.
« My current views on Shellcheck
Programming Bourne shell scripts is tricky, with dim corners »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu Jul 6 20:31:19 2017
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.