From 90d5ddd1f65d8af2c76b14c490c0d2cbf108b3ab Mon Sep 17 00:00:00 2001 From: Robert Thompson Date: Tue, 21 Jan 2020 16:59:28 -0500 Subject: [PATCH] Fix failing tests (@benrimminton: it turned out simple) If the last computed digit of a BinaryFloatingPoint source is > Int.max, we need to add an extra zero digit to the end so we're not negative! --- Sources/BigInt/BigInt.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/BigInt/BigInt.swift b/Sources/BigInt/BigInt.swift index 3d1006d..ec8ebae 100644 --- a/Sources/BigInt/BigInt.swift +++ b/Sources/BigInt/BigInt.swift @@ -358,6 +358,9 @@ extension BigInt: BinaryInteger { float = (float / radix).rounded(.towardZero) } while float != 0 + if let last = words.last, last >= Int.max { + words.append(0) + } self.words = words }