type long integers

I want to use very long intergers. Which type do I use for

integers having 25 million positionen.



Sam1
closed account (48T7M4Gy)
That's a reasonably large number.
What do you plan doing with it? Arithmetic operations of any kind? Just want to look at one?

Maybe a string might be a convenient way to go. (Even then 25*10^6 characters is reasonably large too.)
I want to do arithmetic operations with large integers (25 million positions).

With characters you can't do this, isn't it?

Use an arbitrary precision integer library.

GMP with the civilized boost::multiprecision::mpz_int interface is usually a good choice; (GNU, ergo viral)

boost::multiprecision::cpp_int is truly free (non-viral), but it is somewhat slower.

http://www.boost.org/doc/libs/1_61_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints.html

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <boost/multiprecision/gmp.hpp>
#include <iostream>

int main()
{
    const int one_million = 1'000'000 ;
    boost::multiprecision::mpz_int v2 = 2 ;
    boost::multiprecision::mpz_int v50 = 50 ;
    
    for( int i = 0 ; i < 25 ; ++i ) { v2 *= one_million ; v50 *= one_million ; } 
       
    std::cout << ( v50 - v2 ) / v2  << '\n' ; // 24
}

http://coliru.stacked-crooked.com/a/ff3dcbfd25c2e647
Last edited on
Topic archived. No new replies allowed.