]> Cypherpunks repositories - gostls13.git/commit
math/big: normalize unitialized denominators ASAP
authorRobert Griesemer <gri@golang.org>
Wed, 23 Oct 2019 21:22:32 +0000 (14:22 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 24 Oct 2019 03:34:11 +0000 (03:34 +0000)
commit4412181e7c8b1bfb14b8907c634d61856b97f2de
treea28bec1b5c55c8ab5330f0223699392d236a097a
parent758eb020f72a70e3e42814492daac8719a3be538
math/big: normalize unitialized denominators ASAP

A Rat is represented via a quotient a/b where a and b are Int values.
To make it possible to use an uninitialized Rat value (with a and b
uninitialized and thus == 0), the implementation treats a 0 denominator
as 1.

For each operation we check if the denominator is 0, and then treat
it as 1 (if necessary). Operations that create a new Rat result,
normalize that value such that a result denominator 1 is represened
as 0 again.

This CL changes this behavior slightly: 0 denominators are still
interpreted as 1, but whenever we (safely) can, we set an uninitialized
0 denominator to 1. This simplifies the code overall.

Also: Improved some doc strings.

Preparation for addressing issue #33792.

Updates #33792.

Change-Id: I3040587c8d0dad2e840022f96ca027d8470878a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/202997
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/math/big/rat.go