mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-26 09:14:00 +00:00
typetraits: add toSigned, toUnsigned (#18445)
* typetraits: add toSigned, toUnsigned * improve and add tests Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: flywind <xzsflywind@gmail.com>
This commit is contained in:
@@ -9,8 +9,7 @@
|
||||
|
||||
## Contains the used algorithms for counting bits.
|
||||
|
||||
from std/private/bitops_utils import forwardImpl, toUnsigned
|
||||
|
||||
from std/private/bitops_utils import forwardImpl, castToUnsigned
|
||||
|
||||
const useBuiltins* = not defined(noIntrinsicsBitOpts)
|
||||
const noUndefined* = defined(noUndefinedBitOpts)
|
||||
@@ -65,8 +64,7 @@ func countSetBitsImpl*(x: SomeInteger): int {.inline.} =
|
||||
## Counts the set bits in an integer (also called `Hamming weight`:idx:).
|
||||
# TODO: figure out if ICC support _popcnt32/_popcnt64 on platform without POPCNT.
|
||||
# like GCC and MSVC
|
||||
when x is SomeSignedInt:
|
||||
let x = x.toUnsigned
|
||||
let x = x.castToUnsigned
|
||||
when nimvm:
|
||||
result = forwardImpl(countBitsImpl, x)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user