Introduction
Basic math arithmetic operations
are:
·
Addition
·
Subtraction
·
Multiplication
·
Division
Other math arithmetic operations are Modular, Exponent and etc.
Common calculators and calculator software have input number
size limit, cannot compute very big input number and output very big &
precise number result. Therefore, I write this program that can compute
basic math arithmetic operations on very big numbers input and produce
precise number result.
In programming language, when we write code to perform math
arithmetic on numbers, both input & output numbers are integer. Integer
are signed 32-bit data size. To overcome existing math arithmetic computing
tool data size limit, I used linked-list to store each digit of input &
output of number. Using this way, we can compute very large numbers without
simplifying the digits of input & result, as long as computer hardware
& system can support.
Numbers that having too many digits understandably doesn’t
carry significant senses. We compute math arithmetic using the most
significant digits of the numbers and we will get rationally correct result
in all situations.
Below code demonstrates we can get math arithmetic result while
still able to show all the digits of the result without simplifying the
digits. This code will not able to show every digit of irrational number as
they are infinite decimal numbers. Program will only shows the first 50
most significant decimal.
Visual c#
Console App
Input numbers in
string into static class ‘MathArithmetic.cs’ selected arithmetic operator
to compute and in return obtain number result in string. I use string as
the input number and output number because string have no size limit.
Static class
‘MathArithmetic’ operators’ Addition, Subtraction, Multiplication, Division
and Modular can compute whole number and number with decimal.
‘MathArithmetic’ operator’s Exponent currently can only computer number
with no decimal.
Version 0
Version ‘0’ compute
arithmetic operator single digit by single digit. Each digit of the input
numbers are stored as a node inside the linked-lists.
main_v0.cs.txt MathArithmetic_v0.cs.txt
Version 1
Version ‘1’ compute
arithmetic operator in ‘long integer’ data size.
In Addition,
Subtraction operators, each 18 digits of the input numbers are stored as a
node inside the linked-lists during computation. In Multiplication,
Division, Modular and Exponent arithmetic operator, each 9 digits
of the input numbers are stored as a node inside the linked-lists during
computation.
When computing
Addition, Subtraction and Multiplication arithmetic operation, version ‘1’
(‘MathArithmetic.Addition_UnlimitedDataSize_long’,
‘MathArithmetic.Minus_UnlimitedDataSize_long’,
‘MathArithmetic.Multiplication_UnlimitedDataSize_long’) should be faster
than version ‘0’ (‘MathArithmetic.Addition_UnlimitedDataSize_1Digit’,
‘MathArithmetic.Minus_UnlimitedDataSize_1Digit’,
‘MathArithmetic.Multiplication_UnlimitedDataSize_1Digit’). Because the
program can compute 18 digits or 9 digits numbers in one go.
However when come
to Division and Modular operator, inversely version ‘0’ (‘MathArithmetic.Division_UnlimitedDataSize_1Digit’)
is faster than version ‘1’ (‘MathArithmetic.Division_UnlimitedDataSize_long’).
Version ‘1’ Division operator occasionally need to reiterate many times to
get to the closest number; on the other hands, version ‘0’ Division
operator reiterate maximum 9 times each cycle to get to the closest number.
We can choose to
use either version ‘0’ or version ‘1’ as both of them accept input number
in string format and produce result in string format.
main_v1.cs.txt MathArithmetic_v1.cs.txt
Version 2
In version 1
Division operator, firstly get an approximate outcome, then in each iteration
deduct by 1 to get to the closest number.
Version 2 Division
operator, get an approximate outcome, then in each iteration deduct 1 from the
most significant digits, then to the next digits to get to the closest
number. Therefore version 2 Division operator (‘MathArithmetic.Division_UnlimitedDataSize_long’)
will be faster than version 1 division operator. However,
it is still slower than version 0 Division operator (‘MathArithmetic.Division_UnlimitedDataSize_1Digit’).
main_v2.cs.txt MathArithmetic_v2.cs.txt
|