This commit is contained in:
parent
7b5815358e
commit
e410fe0052
|
@ -49,11 +49,14 @@ func shortLog*(v: FinalityCheckpoints): auto =
|
||||||
|
|
||||||
chronicles.formatIt FinalityCheckpoints: it.shortLog
|
chronicles.formatIt FinalityCheckpoints: it.shortLog
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#integer_squareroot
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/phase0/beacon-chain.md#integer_squareroot
|
||||||
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||||
## Return the largest integer ``x`` such that ``x**2 <= n``.
|
## Return the largest integer ``x`` such that ``x**2 <= n``.
|
||||||
doAssert n >= 0'u64
|
doAssert n >= 0'u64
|
||||||
|
|
||||||
|
if n == high(uint64):
|
||||||
|
return 4294967295'u64
|
||||||
|
|
||||||
var
|
var
|
||||||
x = n
|
x = n
|
||||||
y = (x + 1) div 2
|
y = (x + 1) div 2
|
||||||
|
|
|
@ -21,13 +21,18 @@ import
|
||||||
suite "Spec helpers":
|
suite "Spec helpers":
|
||||||
test "integer_squareroot":
|
test "integer_squareroot":
|
||||||
check:
|
check:
|
||||||
integer_squareroot(0'u64) == 0'u64
|
|
||||||
integer_squareroot(1'u64) == 1'u64
|
integer_squareroot(1'u64) == 1'u64
|
||||||
integer_squareroot(2'u64) == 1'u64
|
integer_squareroot(2'u64) == 1'u64
|
||||||
integer_squareroot(3'u64) == 1'u64
|
integer_squareroot(3'u64) == 1'u64
|
||||||
integer_squareroot(4'u64) == 2'u64
|
integer_squareroot(4'u64) == 2'u64
|
||||||
integer_squareroot(5'u64) == 2'u64
|
integer_squareroot(5'u64) == 2'u64
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/pull/3600
|
||||||
|
integer_squareroot(0'u64) == 0'u64
|
||||||
|
integer_squareroot(100'u64) == 10'u64
|
||||||
|
integer_squareroot(18446744073709551614'u64) == 4294967295'u64
|
||||||
|
integer_squareroot(18446744073709551615'u64) == 4294967295'u64
|
||||||
|
|
||||||
test "build_proof - BeaconState":
|
test "build_proof - BeaconState":
|
||||||
var
|
var
|
||||||
forked = newClone(initGenesisState())
|
forked = newClone(initGenesisState())
|
||||||
|
|
Loading…
Reference in New Issue