2 ms·
So this code is from Go's big.Int documentation (slightly adapted): func main() { a := big.NewInt(0) b := big.NewInt(1) var limit
by fauigerzigerk 8y ago
So this code is from Go's big.Int documentation (slightly adapted):
func main() {
a := big.NewInt(0)
b := big.NewInt(1)
var limit big.Int
limit.Exp(big.NewInt(10), big.NewInt(99), nil)
for a.Cmp(&limit) < 0 {
a.Add(a, b)
a, b = b, a
}
fmt.Println(a)
}
I can't say I'm particularly keen on having to read
a.Cmp(&limit) < 0
instead of
a < limit
The question is whether it's worth it to write code like this in order to prevent others from misusing operator overloading. I guess it may depend on how much math code you write and how disciplined your coworkers are.