ix

Due Friday, 24 Oct. at 1440 ET.

Setup

Requirements

  • To complete this assignment, you must:
    • Create a 72 directory in your 271rs repository.
    • This folder must be a Cargo package.
    • As a convenience, I named mine bignum just to call it something other than ix, which was confusing.
    cargo new 72 --name bignum --vcs none

My responsibility

  • I have provided a completing testing framework within the I/O lab.

Your responsibility

  • You will implement:
    • add_ix
    • sub_ix
    • mul_ix
  • You will attempt, but regard as a challenge problem:
    • div_ix and rem_ix, which are likely wrappers on the same “divmod” helper function.

Tester

DEBUG = 0
CMD = "cargo run --"

import subprocess, os, random
from operator import add, sub, mul, floordiv as quo, mod as rem

bigone, bigtwo = random.randint(2 ** 500, 2 ** 512), random.randint(2 ** 500, 2 ** 512)
hexone, hextwo = hex(bigone), hex(bigtwo)
DEBUG and print("\nhexone =\n", hexone, "\nhextwo = \n", hextwo)

from operator import add, sub, mul, floordiv as quo, mod as rem
ops = {'ADD':add,'SUB':sub,'MUL':mul,'QUO':quo,'REM':rem}
for op in ops:
    result = int(subprocess.check_output(["cargo", "run", hexone, hextwo, op]),16)
    answer = ops[op](bigone,bigtwo)
    if result != answer:
        print("Operator", op, "failed.")
        DEBUG and print("Expected:")
        DEBUG and print(hex(answer))
        DEBUG and print("Received:")
        DEBUG and print(hex(result))
        exit()
    else:
        print(op, "passes.")