summaryrefslogtreecommitdiff
path: root/number.cpp
AgeCommit message (Collapse)Author
2017-11-20Allow left-shifts of more than 32 bitsOlivier Gayot
Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Added bool operator and ! operatorOlivier Gayot
We can now check if a number evaluates to false or true by doing a conversion to bool or use the ! operator. Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Replaced dumb multiplication algorithm by long multiplicationOlivier Gayot
Long multiplication is the multiplication algorithm that is being taught to children in grade school. Although it is very slow compared to Karatsuba algorithm, it is still much faster than the dumb algorithm previously used. Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Allowed construction of number from 64-bits-wide integerOlivier Gayot
Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Added the left-shift computationOlivier Gayot
Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Fixed addition with operands of different sizesOlivier Gayot
When two numbers (i.e. their _operands list) had different sizes, their addition was resulting in undefined behaviour because, at some point in the computation, we were dereferencing the iterator of the shortest number (and the iterator was _operands.cend()). Fixed by virtually "padding" the shortest number with zeros. Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Allow conversion of number to 32 bits integerOlivier Gayot
The method to_uint32() converts a number to a 32-bits-wide integer. The function throws if number cannot be represented using only a single 32-bits-wide integer. Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Added multiplication of two numbersOlivier Gayot
We are using an easy to implemented but extremely slow algorithm to compute the multiplication of two numbers of size n. Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Added pre-increment operator and += operatorOlivier Gayot
Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Added constructors to copy and create a number from an integerOlivier Gayot
Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Made use of 32bits integer instead of 64bitsOlivier Gayot
This will allow multiplication to hold the result of the multiplication of two 32 bits integer in a 64 bits integer. Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Allow a number to be used in an ostream objectOlivier Gayot
When a number is streamed into a ostream object, the hexadecimal representation of the number is given to the stream. Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Added functions to print a number as hex or dec stringOlivier Gayot
Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Added the addition of two numbersOlivier Gayot
We're using the grade school addition method to compute the sum of two numbers of size n. Signed-off-by: Olivier Gayot <og@satcom1.com>
2017-11-19Added a class "number" with comparison operatorsOlivier Gayot
Signed-off-by: Olivier Gayot <og@satcom1.com>