diff --git a/chain/types/electionproof.go b/chain/types/electionproof.go index de99d6fcb..8fdc5dc63 100644 --- a/chain/types/electionproof.go +++ b/chain/types/electionproof.go @@ -77,8 +77,7 @@ func expneg(x *big.Int) *big.Int { deno := polyval(expDenoCoef, x) // Q.256 num = num.Lsh(num, precision) // Q.512 - - return num.Div(num, deno) // Q.512 / Q.256 => Q.256 + return num.Div(num, deno) // Q.512 / Q.256 => Q.256 } // polyval evaluates a polynomial given by coefficients `p` in Q.256 format, @@ -143,11 +142,3 @@ func (ep *ElectionProof) ComputeWinCount(power BigInt, totalPower BigInt) uint64 return j } - -func fxToD(x *big.Int) float64 { - deno := big.NewInt(1) - deno = deno.Lsh(deno, 256) - rat := new(big.Rat).SetFrac(x, deno) - f, _ := rat.Float64() - return f -} diff --git a/chain/types/electionproof_test.go b/chain/types/electionproof_test.go index 713652c61..9749e36a4 100644 --- a/chain/types/electionproof_test.go +++ b/chain/types/electionproof_test.go @@ -7,13 +7,21 @@ import ( "testing" ) +func q256ToF(x *big.Int) float64 { + deno := big.NewInt(1) + deno = deno.Lsh(deno, 256) + rat := new(big.Rat).SetFrac(x, deno) + f, _ := rat.Float64() + return f +} + func TestElectionLam(t *testing.T) { p := big.NewInt(64) tot := big.NewInt(128) lam := lambda(p, tot) target := 64. * 5. / 128. - if fxToD(lam) != target { - t.Fatalf("wrong lambda: %f, should be: %f", fxToD(lam), target) + if q256ToF(lam) != target { + t.Fatalf("wrong lambda: %f, should be: %f", q256ToF(lam), target) } }