Add a toUint64 and toInt64 for 32-bit platform (fixes #48)
This commit is contained in:
parent
1c29314d8e
commit
31101a5c5b
16
stint/io.nim
16
stint/io.nim
|
@ -75,12 +75,26 @@ func to*(x: SomeUnsignedInt, T: typedesc[StUint]): T =
|
|||
|
||||
func toInt*(num: Stint or StUint): int {.inline.}=
|
||||
# Returns as int. Result is modulo 2^(sizeof(int)
|
||||
num.data.least_significant_word.int
|
||||
cast[int](num.data.least_significant_word)
|
||||
|
||||
func toUint*(num: Stint or StUint): uint {.inline.}=
|
||||
# Returns as int. Result is modulo 2^(sizeof(int)
|
||||
num.data.least_significant_word
|
||||
|
||||
func toInt64*(num: Stint or StUint): int64 {.inline.}=
|
||||
# Returns as int64. Result is modulo 2^(sizeof(int)
|
||||
when sizeof(uint) == 8:
|
||||
cast[int64](num.data.least_significant_word)
|
||||
else:
|
||||
cast[int64](num.data.least_significant_two_words)
|
||||
|
||||
func toUint64*(num: Stint or StUint): uint64 {.inline.}=
|
||||
# Returns as int. Result is modulo 2^(sizeof(int)
|
||||
when sizeof(uint) == 8:
|
||||
num.data.least_significant_word.uint64
|
||||
else:
|
||||
cast[uint64](num.data.least_significant_two_words)
|
||||
|
||||
func readHexChar(c: char): int8 {.inline.}=
|
||||
## Converts an hex char to an int
|
||||
case c
|
||||
|
|
|
@ -53,6 +53,11 @@ macro second_least_significant_word*(x: UintImpl or IntImpl): untyped =
|
|||
asWordsImpl(x, x, words)
|
||||
result = words[words.len - 2]
|
||||
|
||||
macro least_significant_two_words*(x: UintImpl or IntImpl): untyped =
|
||||
var words = nnkBracket.newTree()
|
||||
asWordsImpl(x, x, words)
|
||||
result = nnkBracket.newTree(words[words.len - 2], words[words.len - 1])
|
||||
|
||||
# #########################################################################
|
||||
# Iteration macros
|
||||
|
||||
|
|
Loading…
Reference in New Issue