Skip to content

Add Cmp64, Equals, and Equals64

Luke Champine requested to merge currency into master

Curious to see what people think about these. Took like 2 minutes to make these changes using gofmt -w -r so I won't be offended if we decide to reject them. If we do decide to add them, I'll write tests for the new functions.

I think there's a good case for Cmp64, but less so for Equals. The reason being that Equals exists alongside Cmp, which could be confusing since it's just a special case. We could go all the way and replace Cmp with a handful of comparison functions, but then you need separate functions for both < and <=. So you'd wind up with:

  • Equals
  • LessThan
  • LessThanOrEqualTo (AtMost?)
  • GreaterThan
  • GreaterThanOrEqualTo (AtLeast?)

...plus 64 variants for all of them. That feels like too much, but I'm not totally sure. As far as readability goes, I'm sure we can agree that x.Equals(y) is much nicer than x.Cmp(y) == 0.

Merge request reports