mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
* typetraits: add toSigned, toUnsigned * improve and add tests Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: flywind <xzsflywind@gmail.com>
15 lines
278 B
Nim
15 lines
278 B
Nim
import std/private/bitops_utils
|
|
|
|
template chk(a, b) =
|
|
let a2 = castToUnsigned(a)
|
|
doAssert a2 == b
|
|
doAssert type(a2) is type(b)
|
|
doAssert type(b) is type(a2)
|
|
|
|
chk 1'i8, 1'u8
|
|
chk -1'i8, 255'u8
|
|
chk 1'u8, 1'u8
|
|
chk 1'u, 1'u
|
|
chk -1, cast[uint](-1)
|
|
chk -1'i64, cast[uint64](-1)
|