Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
krux02 committed Oct 10, 2019
1 parent 84c956d commit 93dd9ca
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 93dd9ca

Please sign in to comment.