Skip to content

Conversation

LiarPrincess
Copy link

Please read the #242 Using tests from “Violet - Python VM written in Swift” before.


đź’€ Crash

func test_div_crash() {
  let lhs = BigInt("-9223372036854775808")!
  let rhs = BigInt("-1")!
  _ = lhs / rhs // Overflow
}

❌ Failures

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)
}

@LiarPrincess LiarPrincess changed the title # [BigInt tests] đź’€ Binary *, / and % [BigInt tests] đź’€ Binary *, / and % Jan 18, 2023
@LiarPrincess
Copy link
Author

LiarPrincess commented Feb 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant