Fix endianness issue in toInt64 and toUint64

This commit is contained in:
mratsim 2018-10-08 16:27:09 +02:00 committed by tersec
parent 5980477e0b
commit 53ceaffdfa
2 changed files with 5 additions and 2 deletions

View File

@ -56,7 +56,10 @@ macro second_least_significant_word*(x: UintImpl or IntImpl): untyped =
macro least_significant_two_words*(x: UintImpl or IntImpl): untyped = macro least_significant_two_words*(x: UintImpl or IntImpl): untyped =
var words = nnkBracket.newTree() var words = nnkBracket.newTree()
asWordsImpl(x, x, words) asWordsImpl(x, x, words)
when system.cpuEndian == bigEndian:
result = nnkBracket.newTree(words[words.len - 2], words[words.len - 1]) result = nnkBracket.newTree(words[words.len - 2], words[words.len - 1])
else:
result = nnkBracket.newTree(words[words.len - 1], words[words.len - 2])
# ######################################################################### # #########################################################################
# Iteration macros # Iteration macros

View File

@ -137,7 +137,7 @@ suite "Testing input and output procedures":
x.toUint == 2'u^32 + 1 x.toUint == 2'u^32 + 1
x.toUint64 == 2'u64^32 + 1 x.toUint64 == 2'u64^32 + 1
else: else:
echo " Skipped when Stint forces uint32 backend in test mode" echo "Next test skipped when Stint forces uint32 backend in test mode"
suite "Testing conversion functions: Hex, Bytes, Endianness using secp256k1 curve": suite "Testing conversion functions: Hex, Bytes, Endianness using secp256k1 curve":