I am trying to make a very accurate mathematical calculation of a very large / small number. A very large number can have 10 to 50 digits, and a very small number can have 10 to 50 decimal places. Can C ++ do this? If there is no other programming language that can handle such a number?
C ++ can do this using a library, such as the GNU Multipoint Arithmetic Library .
, . , .
, double ++, . wikipedia, .
double
: . , 50 , . , , . , , .
, ++ , Mathematica, Maple , Maxima, Sage , , .
, ( ) Haskell, Icon, Python, Scheme Smalltalk, . , , . , , - , . , , . , C ++ GNU GMP Dave Hanson C .
++, Haskell, , QuickCheck, , .
, python (http://python.org) ruby (http://ruby-lang.org), , , . , ++.
, .
You can use strings that are slow but neat. Here is the add code I made ...
string add(string a, string b){ if(b[0]-'0' == 0 && b.length() == 1){ return a; } int len = max(a.length(), b.length())+1; int ar[len]; int br[len]; int buffer[len]; for(int i = 0; i < len; i++){ ar[i] = 0; br[i] = 0; buffer[i] = 0; } for(int i = 0; i < a.length(); i++){ ar[i] = a[a.length()-i-1]-'0'; } for(int i = 0; i < b.length(); i++){ br[i] = b[b.length()-i-1]-'0'; } // Now we need to add the numbers and add them to the buffer: for(int i = 0; i < len-1; i++){ buffer[i] = ar[i]+br[i]; } for(int i = 0; i < len-1; i++){ if(buffer[i] > 9){ string temp = convertInt(buffer[i]); int first_int = temp[0]-'0'; int second_int = temp[1]-'0'; buffer[i+1] = buffer[i+1]+first_int; buffer[i] = second_int; } } stringstream r; bool num_before = false; for(int i = len-1; i >= 0; i--){ if(buffer[i] == 0 && num_before){ r << buffer[i]; } else if(buffer[i] != 0 && num_before == false){ r << buffer[i]; num_before = true; } else if(buffer[i] != 0 && num_before){ r << buffer[i]; } } return r.str(); } string convertInt(int number) { stringstream ss;//create a stringstream ss << number;//add number to the stream return ss.str();//return a string with the contents of the stream }
Source: https://habr.com/ru/post/1726790/More articles:Listing Index Values - javaCakePHP drops session between pages - phpThe most efficient way to initialize a large doubling block in C - cJquery close function - jquerySQL Select aggregated values in a column - sqlHow to free free code? - licensingTesting with multiple regular expressions at the same time (for use in parsing) - javascriptkernel stack and user-mode application stack - language-agnosticASP.NET with Javascript disabled - javascriptASP.NET URL Redirection - asp.netAll Articles