add is_power_of_2 implementation
This commit is contained in:
parent
4b41010610
commit
94756cc5a2
|
@ -134,4 +134,4 @@ func get_domain*(fork_data: ForkData, slot: uint64, domain_type: uint64): uint64
|
|||
# TODO Slot overflow? Or is slot 32 bits for all intents and purposes?
|
||||
(get_fork_version(fork_data, slot) shl 32) + domain_type
|
||||
|
||||
func is_power_of_2*(v: uint64): bool = discard # TODO
|
||||
func is_power_of_2*(v: uint64): bool = (v and (v-1)) == 0
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
import
|
||||
./test_beaconstate,
|
||||
./test_block_processing,
|
||||
./test_helpers,
|
||||
./test_ssz,
|
||||
./test_validator
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import
|
||||
sequtils, unittest,
|
||||
./testhelpers,
|
||||
./testutil,
|
||||
../beacon_chain/extras,
|
||||
../beacon_chain/spec/[beaconstate, datatypes, digest]
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import
|
||||
options, sequtils, unittest,
|
||||
./testhelpers,
|
||||
./testutil,
|
||||
../beacon_chain/spec/[beaconstate, datatypes, digest],
|
||||
../beacon_chain/[extras, state_transition]
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# beacon_chain
|
||||
# Copyright (c) 2018 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import
|
||||
sequtils, unittest,
|
||||
../beacon_chain/spec/[helpers]
|
||||
|
||||
suite "Spec helpers":
|
||||
test "is_power_of_2 should do its job":
|
||||
check:
|
||||
is_power_of_2(1) == true
|
||||
is_power_of_2(2) == true
|
||||
is_power_of_2(3) == false
|
||||
is_power_of_2(4) == true
|
||||
is_power_of_2(not 0'u64) == false
|
Loading…
Reference in New Issue