]> Cypherpunks repositories - gostls13.git/commitdiff
go/constant: use new math/big.IsInt and isUint predicates
authorRobert Griesemer <gri@golang.org>
Wed, 8 Feb 2017 18:56:30 +0000 (10:56 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 8 Feb 2017 19:13:19 +0000 (19:13 +0000)
Slightly cleaner and more readable code.

Change-Id: I35263dbf338861b0a1bd62d59417b6a2c6a4e670
Reviewed-on: https://go-review.googlesource.com/36562
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/go/constant/value.go

index 7c32473c616503848557440ac46427e03286e244..e9b6087baead519657d0836e2cc581c1b85c343f 100644 (file)
@@ -205,13 +205,8 @@ func rtof(x ratVal) floatVal {
 
 func vtoc(x Value) complexVal { return complexVal{x, int64Val(0)} }
 
-var (
-       minInt64 = big.NewInt(-1 << 63)
-       maxInt64 = big.NewInt(1<<63 - 1)
-)
-
 func makeInt(x *big.Int) Value {
-       if minInt64.Cmp(x) <= 0 && x.Cmp(maxInt64) <= 0 {
+       if x.IsInt64() {
                return int64Val(x.Int64())
        }
        return intVal{x}
@@ -413,7 +408,7 @@ func Uint64Val(x Value) (uint64, bool) {
        case int64Val:
                return uint64(x), x >= 0
        case intVal:
-               return x.val.Uint64(), x.val.Sign() >= 0 && x.val.BitLen() <= 64
+               return x.val.Uint64(), x.val.IsUint64()
        case unknownVal:
                return 0, false
        default: