Skip to content

Commit

Permalink
fixes nim-lang#12514 (nim-lang#12520) [backport]
Browse files Browse the repository at this point in the history
  • Loading branch information
krux02 authored and kiyolee committed Nov 7, 2019
1 parent e9c99e2 commit 3356745
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions compiler/int128.nim
Expand Up @@ -407,11 +407,17 @@ proc divMod*(dividend, divisor: Int128): tuple[quotient, remainder: Int128] =

if divisor > dividend:
result.quotient = Zero
result.remainder = dividend
if isNegativeA:
result.remainder = -dividend
else:
result.remainder = dividend
return

if divisor == dividend:
result.quotient = One
if isNegativeA xor isNegativeB:
result.quotient = NegOne
else:
result.quotient = One
result.remainder = Zero
return

Expand Down Expand Up @@ -685,3 +691,13 @@ when isMainModule:
doAssert divMod(toInt128(-ma),toInt128( mb)) == (toInt128(-ma div mb), toInt128(-ma mod mb))
doAssert divMod(toInt128( ma),toInt128(-mb)) == (toInt128( ma div -mb), toInt128( ma mod -mb))
doAssert divMod(toInt128(-ma),toInt128(-mb)) == (toInt128(-ma div -mb), toInt128(-ma mod -mb))

doAssert divMod(toInt128( mb),toInt128( mb)) == (toInt128( mb div mb), toInt128( mb mod mb))
doAssert divMod(toInt128(-mb),toInt128( mb)) == (toInt128(-mb div mb), toInt128(-mb mod mb))
doAssert divMod(toInt128( mb),toInt128(-mb)) == (toInt128( mb div -mb), toInt128( mb mod -mb))
doAssert divMod(toInt128(-mb),toInt128(-mb)) == (toInt128(-mb div -mb), toInt128(-mb mod -mb))

doAssert divMod(toInt128( mb),toInt128( ma)) == (toInt128( mb div ma), toInt128( mb mod ma))
doAssert divMod(toInt128(-mb),toInt128( ma)) == (toInt128(-mb div ma), toInt128(-mb mod ma))
doAssert divMod(toInt128( mb),toInt128(-ma)) == (toInt128( mb div -ma), toInt128( mb mod -ma))
doAssert divMod(toInt128(-mb),toInt128(-ma)) == (toInt128(-mb div -ma), toInt128(-mb mod -ma))

0 comments on commit 3356745

Please sign in to comment.