types: Rename rational.Evaluate to rational.Round (#1487)
* rational.Evaluate -> rational.RoundInt64 * rational.EvaluateInt -> rational.RoundInt This done to improve clarity of the code. Closes #1485
This commit is contained in:
+5
-5
@@ -174,20 +174,20 @@ func (r Rat) EvaluateBig() *big.Int {
|
||||
return d
|
||||
}
|
||||
|
||||
// evaluate the rational using bankers rounding
|
||||
func (r Rat) Evaluate() int64 {
|
||||
// RoundInt64 rounds the rational using bankers rounding
|
||||
func (r Rat) RoundInt64() int64 {
|
||||
return r.EvaluateBig().Int64()
|
||||
}
|
||||
|
||||
// EvaulateInt evaludates the rational using EvaluateBig
|
||||
func (r Rat) EvaluateInt() Int {
|
||||
// RoundInt round the rational using bankers rounding
|
||||
func (r Rat) RoundInt() Int {
|
||||
return NewIntFromBigInt(r.EvaluateBig())
|
||||
}
|
||||
|
||||
// round Rat with the provided precisionFactor
|
||||
func (r Rat) Round(precisionFactor int64) Rat {
|
||||
rTen := Rat{new(big.Rat).Mul(r.Rat, big.NewRat(precisionFactor, 1))}
|
||||
return Rat{big.NewRat(rTen.Evaluate(), precisionFactor)}
|
||||
return Rat{big.NewRat(rTen.RoundInt64(), precisionFactor)}
|
||||
}
|
||||
|
||||
// TODO panic if negative or if totalDigits < len(initStr)???
|
||||
|
||||
@@ -168,8 +168,8 @@ func TestEvaluate(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
require.Equal(t, tc.res, tc.r1.Evaluate(), "%v", tc.r1)
|
||||
require.Equal(t, tc.res*-1, tc.r1.Mul(NewRat(-1)).Evaluate(), "%v", tc.r1.Mul(NewRat(-1)))
|
||||
require.Equal(t, tc.res, tc.r1.RoundInt64(), "%v", tc.r1)
|
||||
require.Equal(t, tc.res*-1, tc.r1.Mul(NewRat(-1)).RoundInt64(), "%v", tc.r1.Mul(NewRat(-1)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ type Validator interface {
|
||||
func ABCIValidator(v Validator) abci.Validator {
|
||||
return abci.Validator{
|
||||
PubKey: tmtypes.TM2PB.PubKey(v.GetPubKey()),
|
||||
Power: v.GetPower().Evaluate(),
|
||||
Power: v.GetPower().RoundInt64(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user