bitops_utils.nim 541 B

123456789101112131415161718
  1. template forwardImpl*(impl, arg) {.dirty.} =
  2. when sizeof(x) <= 4:
  3. when x is SomeSignedInt:
  4. impl(cast[uint32](x.int32))
  5. else:
  6. impl(x.uint32)
  7. else:
  8. when x is SomeSignedInt:
  9. impl(cast[uint64](x.int64))
  10. else:
  11. impl(x.uint64)
  12. template toUnsigned*(x: int8): uint8 = cast[uint8](x)
  13. template toUnsigned*(x: int16): uint16 = cast[uint16](x)
  14. template toUnsigned*(x: int32): uint32 = cast[uint32](x)
  15. template toUnsigned*(x: int64): uint64 = cast[uint64](x)
  16. template toUnsigned*(x: int): uint = cast[uint](x)