Skip to content

Commit

Permalink
fix nim-lang#12332 (nim-lang#12402) [backport]
Browse files Browse the repository at this point in the history
(cherry picked from commit 0a29c05)
  • Loading branch information
krux02 authored and narimiran committed Oct 12, 2019
1 parent 2ebd470 commit 63d710f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion compiler/int128.nim
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ proc divMod*(dividend, divisor: Int128): tuple[quotient, remainder: Int128] =
result.quotient = -quotient
else:
result.quotient = quotient
if isNegativeB:
if isNegativeA:
result.remainder = -dividend
else:
result.remainder = dividend
Expand Down Expand Up @@ -676,3 +676,12 @@ when isMainModule:

doAssert $high(Int128) == "170141183460469231731687303715884105727"
doAssert $low(Int128) == "-170141183460469231731687303715884105728"

var ma = 100'i64
var mb = 13

# sign correctness
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(-ma),toInt128(-mb)) == (toInt128(-ma div -mb), toInt128(-ma mod -mb))

0 comments on commit 63d710f

Please sign in to comment.