Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Jevin Olano
- // jolano
- // CSE 101
- // November 9, 2019
- // BigInteger.h
- #ifndef _BIGINTEGER_H_INCLUDE_
- #define _BIGINTEGER_H_INCLUDE_
- // Constructors & Destructors ---------------------------
- // BigIntegerObj
- typedef struct BigIntegerObj {
- List number;
- int sign;
- } BigIntegerObj;
- typedef struct BigIntegerObj* BigInteger;
- // newBigInteger()
- // Returns a reference to a new BigInteger object in the zero state.
- BigInteger newBigInteger();
- // freeBigInteger()
- // Frees heap memory associated with *pN, sets *pN to NULL.
- void freeBigInteger(BigInteger* pN);
- // Access Functions -------------------------------------
- // sign()
- // Returns -1 if N is negative, 1 if N is positive, and 0 if N is in the zero state.
- int sign(BigInteger N);
- // compare()
- // Returns -1 if A<B, 1 if A>B, and 0 if A=B.
- int compare(BigInteger A, BigInteger B);
- // equals()
- // Return true (1) if A and B are equal, false (0) otherwise.
- int equals(BigInteger A, BigInteger B);
- // Manipulation Procedures ------------------------------
- // makeZero()
- // Re-sets N to the zero state.
- void makeZero(BigInteger N);
- // negate()
- // Reverses the sign of N: positive <--> negative. Does nothing if N is in the zero state.
- void negate(BigInteger N);
- // BigInteger Arithmetic Operations ---------------------
- // stringToBigInteger()
- // Returns a reference to a new BigInteger represented in base 10 by the string s.
- // Pre: s is a non-empty string containing only base ten digits {0,1,2,3,4,5,6,7,8,9}
- // and an optional sign {+, -} prefix.
- BigInteger stringToBigInteger(char* s);
- // copy()
- // Returns a reference to a new BigInteger object in the same state as N.
- BigInteger copy(BigInteger N);
- // add()
- // Places the sum of A and B in the existing BigInteger S, overwriting its current state: S = A + B
- void add(BigInteger S, BigInteger A, BigInteger B);
- // sum()
- // Returns a reference to a new BigInteger object representing A + B.
- BigInteger sum(BigInteger A, BigInteger B);
- // subtract()
- // Places the difference of A and B in the existing BigInteger D, overwriting its current state: D = A - B
- void subtract(BigInteger D, BigInteger A, BigInteger B);
- // diff()
- // Returns a reference to a new BigInteger object representing A - B.
- BigInteger diff(BigInteger A, BigInteger B);
- // multiply()
- // Places the product of A and B in the existing BigInteger P, overwriting its current state: P = A * B
- void multiply(BigInteger P, BigInteger A, BigInteger B);
- // prod()
- // Returns a reference to a new BigInteger object representing A * B.
- BigInteger prod(BigInteger A, BigInteger B);
- // Other Operations -------------------------------------
- // printBigInteger()
- // Prints a base 10 string representation of N to filestream out.
- void printBigInteger(FILE* out, BigInteger N);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement