Class MPInt

java.lang.Object
   |
   +----MPInt

public class MPInt
extends Object
[ Math 220 main page ] This is a data type for multi-precision integers of arbitrary sign. Its important data are (1) an array of digits a and (2) a sign s. Also, for convenience the size n of the sub-array of significant digits is maintained.

Here is a very simple sample program which multiplies its two arguments.


Variable Index

 o a
 o n
 o sign

Constructor Index

 o MPInt(int)
Constructs a multi-precision integer from a standard Java int.
 o MPInt(int[])
Constructs a non-negative multi-precision integer from an array of digits.
 o MPInt(int[], int)
Allows a sign as well.
 o MPInt(String)
Constructs an integer from a string of decimal digits.

Method Index

 o dividedBy(MPInt)
 o factorial(int)
 o minus(MPInt)
 o modulo(MPInt)
 o plus(MPInt)
This is one of the usual arithmetic operations.
 o times(MPInt)
 o toString()
This function is called implicitly when you print a variable of type MPInt.

Variables

 o a
 public int a[]
 o n
 public int n
 o sign
 public int sign

Constructors

 o MPInt
 public MPInt(String s) throws NumberFormatException
Constructs an integer from a string of decimal digits.

 o MPInt
 public MPInt(int n)
Constructs a multi-precision integer from a standard Java int.

 o MPInt
 public MPInt(int a[])
Constructs a non-negative multi-precision integer from an array of digits.

 o MPInt
 public MPInt(int a[],
              int s)
Allows a sign as well.

Methods

 o plus
 public MPInt plus(MPInt y)
This is one of the usual arithmetic operations. They all can be combined as the ordinary symbolic operations. They associate to the left. Thus a.plus(b).times(c) is (a+b)*c, while a.plus(b.times(c)) is (a+(b*c)).

 o minus
 public MPInt minus(MPInt y)
 o times
 public MPInt times(MPInt y)
 o dividedBy
 public MPInt dividedBy(MPInt y) throws ArithmeticException
 o modulo
 public MPInt modulo(MPInt y) throws ArithmeticException
 o toString
 public String toString()
This function is called implicitly when you print a variable of type MPInt. For example if a is an MPInt then System.out.println(a) will print out this string.

Overrides:
toString in class Object
 o factorial
 public static MPInt factorial(int n) throws ArithmeticException