I have a very large number, assume some transaction id or big money involved. So, how I will handle the calculation on these ( add, multiple etc). Does any other was to store it in the generic storage type( long, long long etc) to take care of such situation? Does boost support the solution?
问题:
回答1:
You use a library that handles big numbers, like The GNU Multiple Precision Arithmetic Library which seems to be the most common. Or if you want Boost specifically, there's always the Multiprecision library (which can use GMP as backend).
回答2:
Please check boost multiprecision library .. It will be handy if your project is already using boost. boost multiprecision library
回答3:
The closest to a standard is The GNU Multiple Precision Arithmetic Library.
回答4:
you can Wrote a large number of classes handle the calculation. use the Array of characters store your data.
回答5:
If your numbers are larger than int, long or double. Use type long long and do not worry about adding, multiplication etc.
- long long largenum = 100000000000LL
回答6:
For This Question We Should Create a
Divided And Conquer Recursive Function And I Show You
How You can Do That :
Problem = Multiple U*V Tow 100 Digit numbers ..
Function Output = (Prod) Return U*V
Long Long Long Integer Numbers ...
Like 9999999999999999*99999999999999999
Create Class Like That in your Programming Language ..
{
large.integer x,y,w,z;
int m,n;
n = max("Digits of Number" u , "Digits Of Number" v)
if(u == 0 || v == 0)
{
return 0;
}
else if (n {
return (u*v);
}else
{
m= n/2; // n = Digits Of Number u
x= u div (10^m);
y= u rem (10^m);
w = v div (10^m);
z= v rem (10^m);
return prod(x,w) * (10^ (2*m)) + prod(x,z) + prod(w,y) * (10^m) + prod(y,z);
}
}
}
In This Project t(n) = 4t(n/2) + CN !!
Sample For Tow Little Number In Mathematica :
4795 * 2412 = ?
n =4 (Digits of 4795)
Result :
(47 * 10^2 +95) * (24 * 10^2 + 12) =>
=> (47 * 24 * 10^4) + (47 * 12 * 10^2)+ (95 * 24 * 10^2) + 95 *12
=> 47 *24 * 10^4 + 47*12 + 95 * 24 + 10^2 + 95 * 12 = Result Of Function
Best Regards Aj.Duende (Persian Guy)