Skip to content

Commit ea4e548

Browse files
committed
added test for multiplication and relative fix
1 parent 08b3c9c commit ea4e548

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/bigints.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ proc multiplicationInt(a: var BigInt, b: BigInt, c: int32) =
476476

477477
# This doesn't work when a = b
478478
proc multiplication(a: var BigInt, b, c: BigInt) =
479+
if b.isZero or c.isZero:
480+
a = zero
481+
return
479482
let
480483
bl = b.limbs.len
481484
cl = c.limbs.len
@@ -487,9 +490,6 @@ proc multiplication(a: var BigInt, b, c: BigInt) =
487490
else:
488491
unsignedMultiplication(a, b, c, bl, cl)
489492

490-
if a.limbs == @[0'u32]:
491-
return
492-
493493
if Negative in b.flags:
494494
if Negative in c.flags:
495495
a.flags.excl(Negative)

tests/tester.nim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,19 @@ test "empty limbs when uninitialized (https://github.com/def-/nim-bigints/issues
201201
check -bigOne - -zeroEmpty == -bigOne # ok
202202
check zeroEmpty - -bigOne == bigOne # ok
203203
check -zeroEmpty - -bigOne == bigOne # ok
204+
205+
# multiplication
206+
check zeroEmpty * 1.int32 == zero
207+
check -zeroEmpty * 1.int32 == zero
208+
check zeroEmpty * one == zero
209+
check -zeroEmpty * one == zero
210+
check one * zeroEmpty == zero
211+
check one * -zeroEmpty == zero
212+
213+
# https://github.com/def-/nim-bigints/issues/26
214+
block:
215+
var
216+
a: BigInt
217+
b: BigInt = 12.initBigInt
218+
219+
check a*b == 0

0 commit comments

Comments
 (0)