7f1ef49 [release-branch.go1.13] math/big: normalize unitialized denominators ASAP

1 file Authored by Robert Griesemer 3 years ago, Committed by Dmitri Shuralyov 3 years ago,
    [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>
    
        
file modified
+28 -27