Exercise #6: An Integers module

The handout on bignums claims that it's straightforward to implement all of the operations on integers listed in the handout on integers, using a signed-magnitude representation of integers in which the magnitude is a bignum. The assignment for this week is to justify this claim by designing, writing, and testing an Integers module containing such an implementation.

Specifically, your module should export at least the type identifier Int and the following procedures and functions:

function NegateInt (Negand: Int): Int;

function AbsoluteValueOfInt (Operand: Int): Int;

function AddInt (Augend, Addend: Int): Int;

function SubtractInt (Minuend, Subtrahend: Int): Int;

function MultiplyInt (Multiplicand, Multiplier: Int): Int;

procedure DivideInt (Dividend, Divisor: Int; var Quotient, Remainder: Int);

function QuotientInt (Dividend, Divisor: Int): Int;

function RemainderInt (Dividend, Divisor: Int): Int;

function ModuloInt (Moduland, Modulus: Int): Int;

function RaiseInt (Base: Int; Exponent: Natural): Int;

function SuccessorOfInt (Operand: Int): Int;

function PredecessorOfInt (Operand: Int): Int;

function TwiceInt (Operand: Int): Int;

function SquareInt (Operand: Int): Int;

function CubeInt (Operand: Int): Int;

function EqualInts (LeftOperand, RightOperand: Int): Boolean;

function UnequalInts (LeftOperand, RightOperand: Int): Boolean;

function LessInt (LeftOperand, RightOperand: Int): Boolean;

function LessOrEqualInt (LeftOperand, RightOperand: Int): Boolean;

function GreaterInt (LeftOperand, RightOperand: Int): Boolean;

function GreaterOrEqualInt (LeftOperand, RightOperand: Int): Boolean;

function MajorInt (LeftOperand, RightOperand: Int): Int;

function MinorInt (LeftOperand, RightOperand: Int): Int;

function ZeroInt (Operand: Int): Boolean;

function NegativeInt (Operand: Int): Boolean;

function PositiveInt (Operand: Int): Boolean;

function MultipleInt (Candidate, Unit: Int): Boolean;

function EvenInt (Operand: Int): Boolean;

function OddInt (Operand: Int): Boolean;

procedure ReadInt (var Source: Text; var Legend: Int; var Success: Boolean);

procedure WriteInt (var Target: Text; Scribend: Int);

function PascalIntegerToInt (N: Integer): Int;

function IntToPascalInteger (N: Int): Integer;

procedure AssignInt (var Target: Int; Source: Int);
You should submit (1) the source code for the module itself and (2) the source code for a test program that imports this module and thoroughly checks the correctness of each of these procedures and functions.

This assignment will be due on Friday, November 15.


created November 7, 1996
last revised November 7, 1996

John David Stone (stone@math.grin.edu)