Skip to content

[BigInt tests] ❌ Binary + and - #246

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: biginteger
Choose a base branch
from

Conversation

LiarPrincess
Copy link

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


❌ Failures

func test_binarySub() {
  // https://www.wolframalpha.com/input?i=-922337203685477587+-+%28-9223372036854775808%29
  let lhs = BigInt("-922337203685477587")!
  let rhs = BigInt("-9223372036854775808")!
  let expected = BigInt("8301034833169298221")!
  XCTAssertEqual(lhs - rhs, expected)
  // The same on Swift.Int:
  XCTAssertEqual(-922337203685477587 - (-9223372036854775808), 8301034833169298221)
}

func test_binarySub_2() {
  typealias Word = BigIntPrototype.Word

  let intMax = Int.max
  let intMaxAsWord = Word(intMax.magnitude)

  // intMax - (-(Word.max - intMaxAsWord)) =
  // intMax - (-Word.max + intMaxAsWord) =
  // intMax + Word.max - intMaxAsWord =
  // Word.max
  let max = BigInt(intMax)
  let value = BigInt(.negative, magnitude: Word.max - intMaxAsWord)
  let expected = BigInt(.positive, magnitude: Word.max)
  XCTAssertEqual(max - value, expected)
}

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

Successfully merging this pull request may close these issues.

1 participant