]> Cypherpunks repositories - gostls13.git/commitdiff
math/big: implement fast path in Float.SetRat if argument is integer
authorRobert Griesemer <gri@golang.org>
Sun, 15 Feb 2015 05:29:37 +0000 (21:29 -0800)
committerRobert Griesemer <gri@golang.org>
Sun, 15 Feb 2015 20:11:00 +0000 (20:11 +0000)
Change-Id: Ib82500e198b86e9fade278c7eea7a4b0c6b0b2e1
Reviewed-on: https://go-review.googlesource.com/4921
Reviewed-by: Rob Pike <r@golang.org>
src/math/big/float.go

index 739d30f7ad50ee9190ea07710c94dceeccccdaca..877379c901befd8e188f3d2be550541e596195f4 100644 (file)
@@ -582,7 +582,9 @@ func (z *Float) SetInt(x *Int) *Float {
 // If z's precision is 0, it is changed to the largest of a.BitLen(),
 // b.BitLen(), or 64; with x = a/b.
 func (z *Float) SetRat(x *Rat) *Float {
-       // TODO(gri) can be more efficient if x is an integer
+       if x.IsInt() {
+               return z.SetInt(x.Num())
+       }
        var a, b Float
        a.SetInt(x.Num())
        b.SetInt(x.Denom())