A custom made proof-of-concept class for arbitrary precision arithmetic.
Supports only integers.
Capitalised variables indicate `LongNumber` objects. Lower case variables indicate `int`s or `long`s.
| Operation | Function/ Operator |
Example | Notes |
|---|---|---|---|
| Input | >> |
std::cin >> X; |
|
| Output | << |
std::cout << X; |
|
| Assignment | = |
X = y;X = 123;X = "-112"; |
Can equate with a long, LongNumber or a std::string. Will throw a InvalidInputException if it is unable to parse the string. |
| Comparison | <>==!= |
X < Y;X > 1123;X == y;X != 0; |
Can compare a LongNumber with other LongNumbers, as well as longs and std::strings. Can use combined comparisons like <= or >=. |
| Addition | ++=++ |
X + y;X + Y;X += Y;X++;++X; |
Can add with longs as well as LongNumbers. Each notation has its standard meaning. |
| Subtraction | --=-- |
X - y;X - Y;X -= Y;X--;--X; |
Can subtract longs as well as LongNumbers from the LongNumber. Each notation has its standard meaning. |
| Multiplication | **= |
X * y;X * Y;X *= Y; |
Can multiply with longs as well as LongNumbers. Each notation has its standard meaning. |
| Division | //= |
X / y;X / Y;X /= Y; |
Can divide with longs as well as LongNumbers. Each notation has its standard meaning. Dividing by zero will throw a DivisionByZero exception. |
| Modulo | %%= |
X % y;X % Y;X %= Y; |
Can find the modulus of LongNumber with longs as well as LongNumbers. Each notation has its standard meaning. Finding the modulus with 0 will throw a DivisionByZero exception. |
| Absolute | absolute() |
X.absolute() |
Returns a LongNumber. Will not change the contents of X. |
| Cast to Long | toLong() |
X.toLong() |
Returns a long. Does not account for overflow. |
| Name | Function |
|---|---|
DivideByZeroException |
Thrown when any attempt is made to divide by 0. |
InvalidInputException |
Thrown when the entered string does not correspond to an integer. |