]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.13] math/big: normalize unitialized denominators ASAP
authorRobert Griesemer <gri@golang.org>
Wed, 23 Oct 2019 21:22:32 +0000 (14:22 -0700)
committerDmitri Shuralyov <dmitshur@golang.org>
Wed, 27 May 2020 22:52:28 +0000 (22:52 +0000)
commit7f1ef49347e6e1f5a51c9ca3e4f4f617c2317042
tree33c47df25d3f9df81c029e45d1c4c57a1e3c9865
parent444ad952c4dd346955362165aa20d0b4938ffcca
[release-branch.go1.13] 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.

For #36689.
For #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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/233322
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/math/big/rat.go