SHARE
TWEET

Untitled

Pweebs Nov 9th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Jevin Olano
  2. // jolano
  3. // CSE 101
  4. // November 9, 2019
  5. // BigInteger.h
  6.  
  7. #ifndef _BIGINTEGER_H_INCLUDE_
  8. #define _BIGINTEGER_H_INCLUDE_
  9.  
  10. // Constructors & Destructors ---------------------------
  11.  
  12. // BigIntegerObj
  13. typedef struct BigIntegerObj {
  14.     List number;
  15.     int sign;
  16. } BigIntegerObj;
  17.  
  18. typedef struct BigIntegerObj* BigInteger;
  19.  
  20. // newBigInteger()
  21. // Returns a reference to a new BigInteger object in the zero state.
  22. BigInteger newBigInteger();
  23.  
  24. // freeBigInteger()
  25. // Frees heap memory associated with *pN, sets *pN to NULL.
  26. void freeBigInteger(BigInteger* pN);
  27.  
  28. // Access Functions -------------------------------------
  29.  
  30. // sign()
  31. // Returns -1 if N is negative, 1 if N is positive, and 0 if N is in the zero state.
  32. int sign(BigInteger N);
  33.  
  34. // compare()
  35. // Returns -1 if A<B, 1 if A>B, and 0 if A=B.
  36. int compare(BigInteger A, BigInteger B);
  37.  
  38. // equals()
  39. // Return true (1) if A and B are equal, false (0) otherwise.
  40. int equals(BigInteger A, BigInteger B);
  41.  
  42. // Manipulation Procedures ------------------------------
  43.  
  44. // makeZero()
  45. // Re-sets N to the zero state.
  46. void makeZero(BigInteger N);
  47.  
  48. // negate()
  49. // Reverses the sign of N: positive <--> negative. Does nothing if N is in the zero state.
  50. void negate(BigInteger N);
  51.  
  52. // BigInteger Arithmetic Operations ---------------------
  53.  
  54. // stringToBigInteger()
  55. // Returns a reference to a new BigInteger represented in base 10 by the string s.
  56. // Pre: s is a non-empty string containing only base ten digits {0,1,2,3,4,5,6,7,8,9}
  57. // and an optional sign {+, -} prefix.
  58. BigInteger stringToBigInteger(char* s);
  59.  
  60. // copy()
  61. // Returns a reference to a new BigInteger object in the same state as N.
  62. BigInteger copy(BigInteger N);
  63.  
  64. // add()
  65. // Places the sum of A and B in the existing BigInteger S, overwriting its current state: S = A + B
  66. void add(BigInteger S, BigInteger A, BigInteger B);
  67.  
  68. // sum()
  69. // Returns a reference to a new BigInteger object representing A + B.
  70. BigInteger sum(BigInteger A, BigInteger B);
  71.  
  72. // subtract()
  73. // Places the difference of A and B in the existing BigInteger D, overwriting its current state: D = A - B
  74. void subtract(BigInteger D, BigInteger A, BigInteger B);
  75.  
  76. // diff()
  77. // Returns a reference to a new BigInteger object representing A - B.
  78. BigInteger diff(BigInteger A, BigInteger B);
  79.  
  80. // multiply()
  81. // Places the product of A and B in the existing BigInteger P, overwriting its current state: P = A * B
  82. void multiply(BigInteger P, BigInteger A, BigInteger B);
  83.  
  84. // prod()
  85. // Returns a reference to a new BigInteger object representing A * B.
  86. BigInteger prod(BigInteger A, BigInteger B);
  87.  
  88. // Other Operations -------------------------------------
  89.  
  90. // printBigInteger()
  91. // Prints a base 10 string representation of N to filestream out.
  92. void printBigInteger(FILE* out, BigInteger N);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top