1
0
mirror of https://github.com/golang/go synced 2024-10-02 16:28:34 -06:00

go/constant: use new math/big.IsInt and isUint predicates

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>
This commit is contained in:
Robert Griesemer 2017-02-08 10:56:30 -08:00
parent ee7fdc2647
commit 92cdde016a

View 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: