Amend divmod (#22131)

* Add Overflow checks & test adjust

* Avoiding nimvm differences in tests

* distinguish DivByZeroDefect
This commit is contained in:
Ryan McConnell
2023-06-20 07:04:34 -04:00
committed by GitHub
parent f524d60fa1
commit db41f04ab0
2 changed files with 17 additions and 5 deletions

View File

@@ -190,10 +190,17 @@ template main() =
block: # divmod
doAssert divmod(int.high, 1) == (int.high, 0)
doAssert divmod(-1073741823, 17) == (-63161283, -12)
when not defined(js):
doAssert divmod(int32.high, 1.int32) == (int32.high, 0.int32)
doAssert divmod(1073741823.int32, 5.int32) == (214748364.int32, 3.int32)
doAssert divmod(4611686018427387903.int64, 5.int64) == (922337203685477580.int64, 3.int64)
doAssert divmod(int32.high, 1.int32) == (int32.high, 0.int32)
doAssert divmod(1073741823.int32, 5.int32) == (214748364.int32, 3.int32)
doAssert divmod(4611686018427387903.int64, 5.int64) == (922337203685477580.int64, 3.int64)
when not defined(js) and (not compileOption("panics")) and compileOption("overflowChecks"):
when nimvm:
discard # cannot catch OverflowDefect here
else:
doAssertRaises(OverflowDefect, (discard divmod(cint.low, -1.cint)))
doAssertRaises(OverflowDefect, (discard divmod(clong.low, -1.clong)))
doAssertRaises(OverflowDefect, (discard divmod(clonglong.low, -1.clonglong)))
doAssertRaises(DivByZeroDefect, (discard divmod(1, 0)))
block: # log
doAssert log(4.0, 3.0) ==~ ln(4.0) / ln(3.0)