From 53ceaffdfa5bbbda4c27657bac55a4f2053ab904 Mon Sep 17 00:00:00 2001 From: mratsim Date: Mon, 8 Oct 2018 16:27:09 +0200 Subject: [PATCH] Fix endianness issue in toInt64 and toUint64 --- stint/private/as_words.nim | 5 ++++- tests/test_io.nim | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/stint/private/as_words.nim b/stint/private/as_words.nim index 79e3d01..0fb774b 100644 --- a/stint/private/as_words.nim +++ b/stint/private/as_words.nim @@ -56,7 +56,10 @@ macro second_least_significant_word*(x: UintImpl or IntImpl): untyped = 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]) + when system.cpuEndian == bigEndian: + 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 diff --git a/tests/test_io.nim b/tests/test_io.nim index 8b0e34f..52bad54 100644 --- a/tests/test_io.nim +++ b/tests/test_io.nim @@ -137,7 +137,7 @@ suite "Testing input and output procedures": x.toUint == 2'u^32 + 1 x.toUint64 == 2'u64^32 + 1 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":