#ifndef _NUM_H #define _NUM_H #include /* * High-precision arithmetic on non-negative number in base 10. */ typedef struct num Num; /* constructs a Num from a string */ /* string contains representation of the number * in base 10, e.g. numCreate("314159"); * Returns a null pointer (0) if the string contains any non-digits. * Leading zeros are OK: numCreate("012") parses as 12. * Empty string parses as 0 */ Num * numCreate(const char *s); /* Free all resources used by a Num */ void numDestroy(Num *n); /* Get the value of the i-th least significant digit of a Num. * Returns 0 if i is out of range. * Example: * n = numCreate("12345"); * numGetDigit(n, 0) == 5 * numGetDigit(n, 3) == 2 * numGetDigit(n, 17) == 0 * numGetDigit(n, -12) == 0 */ int numGetDigit(const Num *n, int i); /* add two Nums, returning a new Num */ /* does not destroy its inputs, caller must destroy output */ Num * numAdd(const Num *x, const Num *y); /* multiply two Nums, returning a new Num */ /* does not destroy its inputs, caller must destroy output */ Num * numMultiply(const Num *x, const Num *y); /* Print the digits of a number to file. * Do not print any leading zeros unless n is zero. */ void numPrint(const Num *n, FILE *f); #endif /* _NUM_H */