What Are the Best (Portable) Cross-Platform Arbitrary-Precision Math Libraries

What are the best (portable) cross-platform arbitrary-precision math libraries?

GMP is the popular choice. Squeak Smalltalk has a very nice library, but it's written in Smalltalk.

You asked for relevant books or articles. The tricky part of bignums is long division. I recommend Per Brinch Hansen's paper Multiple-Length Division Revisited: A Tour of the Minefield.

What's the best (for speed) arbitrary-precision library for C++?

GMPLIB

GMP is a free library for arbitrary precision arithmetic, operating on signed ... C++ class based interface to all of the above.

How to print full integer like in python, in c++?

#include <iostream>

int main()
{
long double d{ 89589789687112168422297691222737771124865819889385981395999564038551674847206437815235099730864284.L };
std::cout << std::fixed << d;
}

Precision of long double is not sufficient to represent the number accurately, though. If you need more you'd have to use a library for arbitrary precision like GMP.

why for loop is not work correctly for a simple multiplication numbers 1 to 50?

I will answer specifically the asked question "Why?" and not the one added in the comments "How?".

You get the result 0 because one of the intermediate values of answer is 0 and multiplying anything with it will stay 0.

Here are the intermediate values (I found them by moving your output into the loop.):

1
2
6
24
120
720
5040
40320
362880
3628800
39916800
479001600
1932053504
1278945280
2004310016
2004189184
-288522240
-898433024
109641728
-2102132736
-1195114496
-522715136
862453760
-775946240
2076180480
-1853882368
1484783616
-1375731712
-1241513984
1409286144
738197504
-2147483648
-2147483648
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

E.g. here https://www.tutorialspoint.com/compile_cpp_online.php

Now to explain why one of them is 0 to begin with:

Because of the values, the sequence of faculties, quickly leaves the value range representable in the chosen data type (note that the number decimal digits does not increase at some point; though the binary digits are the relevant ones).

After that, the values are not really related to the correct values anymore, see them even jumping below zero and back...

... and one of them happens to be 0.

For the "How?" please see the comments (and maybe other, valuable answers).



Related Topics



Leave a reply



Submit