parent
26074f594d
commit
9b0e874687
1 changed files with 3 additions and 6 deletions
|
|
@ -335,7 +335,6 @@ proc `*`(a: Int128, b: uint32): Int128 =
|
||||||
result.udata[3] = cast[uint32](tmp3) + cast[uint32](tmp2 shr 32)
|
result.udata[3] = cast[uint32](tmp3) + cast[uint32](tmp2 shr 32)
|
||||||
|
|
||||||
proc `*`*(a: Int128, b: int32): Int128 =
|
proc `*`*(a: Int128, b: int32): Int128 =
|
||||||
let isNegative = isNegative(a) xor isNegative(b)
|
|
||||||
result = a * cast[uint32](abs(b))
|
result = a * cast[uint32](abs(b))
|
||||||
if b < 0:
|
if b < 0:
|
||||||
result = -result
|
result = -result
|
||||||
|
|
@ -356,8 +355,6 @@ proc low64(a: Int128): uint64 =
|
||||||
bitconcat(a.udata[1], a.udata[0])
|
bitconcat(a.udata[1], a.udata[0])
|
||||||
|
|
||||||
proc `*`*(lhs,rhs: Int128): Int128 =
|
proc `*`*(lhs,rhs: Int128): Int128 =
|
||||||
let isNegative = isNegative(lhs) xor isNegative(rhs)
|
|
||||||
|
|
||||||
let
|
let
|
||||||
a = cast[uint64](lhs.udata[0])
|
a = cast[uint64](lhs.udata[0])
|
||||||
b = cast[uint64](lhs.udata[1])
|
b = cast[uint64](lhs.udata[1])
|
||||||
|
|
@ -379,9 +376,6 @@ proc `*`*(lhs,rhs: Int128): Int128 =
|
||||||
result = result + toInt128(a32 * b00) shl 32
|
result = result + toInt128(a32 * b00) shl 32
|
||||||
result = result + toInt128(a00 * b32) shl 32
|
result = result + toInt128(a00 * b32) shl 32
|
||||||
|
|
||||||
if isNegative != isNegative(result):
|
|
||||||
assert(false, "overflow")
|
|
||||||
|
|
||||||
proc `*=`*(a: var Int128, b: Int128) =
|
proc `*=`*(a: var Int128, b: Int128) =
|
||||||
a = a * b
|
a = a * b
|
||||||
|
|
||||||
|
|
@ -684,6 +678,9 @@ when isMainModule:
|
||||||
var ma = 100'i64
|
var ma = 100'i64
|
||||||
var mb = 13
|
var mb = 13
|
||||||
|
|
||||||
|
doAssert toInt128(ma) * toInt128(0) == toInt128(0)
|
||||||
|
doAssert toInt128(-ma) * toInt128(0) == toInt128(0)
|
||||||
|
|
||||||
# sign correctness
|
# 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))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue