aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMeng-Ying Yang <garfield@dexon.org>2019-04-12 10:45:02 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit66a6bea86c7c007562a51d3720a4f7667ce1b64e (patch)
treecd68aaffdd14b10d102cc6dc7c50a6ec69045e9a
parent34df61db58fcf9c9eb02d20fc9d2f05249c47418 (diff)
downloaddexon-66a6bea86c7c007562a51d3720a4f7667ce1b64e.tar.gz
dexon-66a6bea86c7c007562a51d3720a4f7667ce1b64e.tar.zst
dexon-66a6bea86c7c007562a51d3720a4f7667ce1b64e.zip
core: sqlvm: common: fix decimal limit values
The original limit values are so wrong. We fix the values, rename parameters according to Go's limit values naming rule.
-rw-r--r--core/vm/sqlvm/common/decimal/decimal.go14
-rw-r--r--core/vm/sqlvm/runtime/instructions.go2
2 files changed, 11 insertions, 5 deletions
diff --git a/core/vm/sqlvm/common/decimal/decimal.go b/core/vm/sqlvm/common/decimal/decimal.go
index 96212ed27..390f440e3 100644
--- a/core/vm/sqlvm/common/decimal/decimal.go
+++ b/core/vm/sqlvm/common/decimal/decimal.go
@@ -1,16 +1,22 @@
package decimal
-import "github.com/dexon-foundation/decimal"
+import (
+ "fmt"
+ "math"
+
+ "github.com/dexon-foundation/decimal"
+)
// Shared vars.
var (
False = decimal.New(0, 0)
True = decimal.New(1, 0)
- Int64Max = decimal.New(1, 63).Sub(decimal.One)
- Int64Min = decimal.New(1, 63).Neg()
+ MaxInt64 = decimal.New(math.MaxInt64, 0)
+ MinInt64 = decimal.New(math.MinInt64, 0)
- UInt16Max = decimal.New(1, 16).Sub(decimal.One)
+ MaxUint16 = decimal.New(math.MaxUint16, 0)
+ MaxUint64 = decimal.RequireFromString(fmt.Sprint(uint64(math.MaxUint64)))
)
// Val2Bool convert value to boolean definition.
diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go
index 4b179f4aa..b6b37052e 100644
--- a/core/vm/sqlvm/runtime/instructions.go
+++ b/core/vm/sqlvm/runtime/instructions.go
@@ -347,7 +347,7 @@ func bool2Raw(b bool) (r *Raw) {
}
func value2ColIdx(v decimal.Decimal) (idx uint16) {
- if v.GreaterThan(dec.UInt16Max) {
+ if v.GreaterThan(dec.MaxUint16) {
panic(errors.New("field index greater than uint16 max"))
} else if v.LessThan(decimal.Zero) {
panic(errors.New("field index less than 0"))