Open LiarPrincess opened 1 year ago
Please read the #242 Using tests from “Violet - Python VM written in Swift” before.
func test_div_crash() { let lhs = BigInt("-9223372036854775808")! let rhs = BigInt("-1")! _ = lhs / rhs // Overflow }
func test_div_sign() { // positive / negative = negative var lhs = BigInt("18446744073709551615")! var rhs = BigInt("-1")! var expected = BigInt("-18446744073709551615")! XCTAssertEqual(lhs / rhs, expected) // negative / positive = negative lhs = BigInt("-340282366920938463481821351505477763074")! rhs = BigInt("18446744073709551629")! expected = BigInt("-18446744073709551604")! XCTAssertEqual(lhs / rhs, expected) }
I added the test for rounding toward 0: |quotient * rhs| <= |lhs|, but the current implementation of BigInt.magnitude does not work, so this test will fail though not because of div.
|quotient * rhs| <= |lhs|
BigInt.magnitude
div
Please read the #242 Using tests from “Violet - Python VM written in Swift” before.
đź’€ Crash
❌ Failures