fixedpoint: fix fixedpoint value int64 cast

This commit is contained in:
c9s 2021-06-08 01:12:36 +08:00
parent ecf888dfd6
commit ac71a392c6
2 changed files with 13 additions and 5 deletions

View File

@ -55,7 +55,11 @@ func (v Value) String() string {
}
func (v Value) Int64() int64 {
return int64(v)
return int64(v.Float64())
}
func (v Value) Int() int {
return int(v.Float64())
}
func (v Value) Mul(v2 Value) Value {
@ -82,6 +86,10 @@ func (v Value) Floor() Value {
return NewFromFloat(math.Floor(v.Float64()))
}
func (v Value) Ceil() Value {
return NewFromFloat(math.Ceil(v.Float64()))
}
func (v Value) Sub(v2 Value) Value {
return Value(int64(v) - int64(v2))
}
@ -292,7 +300,7 @@ func NumFractionalDigits(a Value) int {
numPow++
}
numZeros := 0
for v := a.Int64(); v%10 == 0; v /= 10 {
for v := int64(a); v%10 == 0; v /= 10 {
numZeros++
}
return numPow - numZeros

View File

@ -54,10 +54,10 @@ func (slice PriceVolumeSlice) First() (PriceVolume, bool) {
}
func (slice PriceVolumeSlice) IndexByVolumeDepth(requiredVolume fixedpoint.Value) int {
var tv int64 = 0
var tv fixedpoint.Value = 0
for x, el := range slice {
tv += el.Volume.Int64()
if tv >= requiredVolume.Int64() {
tv += el.Volume
if tv >= requiredVolume {
return x
}
}