Rename fxToD
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
f523b17a35
commit
84c0b50aa1
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user