Skip to content

A custom made proof-of-concept class for handling numbers with large number of digits

Notifications You must be signed in to change notification settings

aadityanaik/LongNums

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LongNums

A custom made proof-of-concept class for arbitrary precision arithmetic.
Supports only integers.


Table of Operations

Key for examples-


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.

Exceptions

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.

About

A custom made proof-of-concept class for handling numbers with large number of digits

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published