Rename fxToD

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-06-22 15:13:36 +02:00
parent f523b17a35
commit 84c0b50aa1
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
2 changed files with 11 additions and 12 deletions

View File

@ -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
}

View File

@ -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)
}
}