Big Integers in C++ [Partially solved]

In this forum members can discuss topics about specific programming languages.
Post Reply
Vodkacannon
Posts: 3
Joined: Sat May 26, 2012 3:55 am

Big Integers in C++ [Partially solved]

Post by Vodkacannon » Sat Jun 02, 2012 12:11 am

EDIT: I've found a very simple big integer library, https://mattmccutchen.net/bigint/index.html. But I'm getting errors when I use it with a loop and increment operators.
All of the errors say: Unresolved External Symbol

julfo
Posts: 1
Joined: Thu Aug 09, 2012 8:12 am

Re: Big Integers in C++ [Partially solved]

Post by julfo » Fri Aug 10, 2012 1:21 pm

I've just started learning C++.

I had the same issue as you with that particular library, so I tried ttmath instead (http://ttmath.org) and it works wonderfully, at least as far as I can see.

Hope this helps

Thizda
Posts: 1
Joined: Tue Apr 09, 2013 10:13 pm

Re: Big Integers in C++ [Partially solved]

Post by Thizda » Tue Apr 09, 2013 10:21 pm

If you're compiling with the GNU Compiler Collection (GCC), you can use 'long long int' to declare a 64-bit integer.

You can even use '__int128' to declare a 128-bit integer, according to the GCC online docs (it won't work on x86 architecture, though).

User avatar
AceInfinity
Posts: 2
Joined: Sun Oct 20, 2013 5:13 pm

Re: Big Integers in C++ [Partially solved]

Post by AceInfinity » Sun Oct 20, 2013 6:05 pm

Use the GMP arbitrary precision arithmetic library. It's free, and probably one of the better ones you can use.

Factorial example:

Code: Select all

void Factorial(unsigned n, mpz_t& result)
{
    mpz_set_ui(result, 1);
    for (unsigned i = 1; i <= n; ++i)
        mpz_mul_ui(result, result, i);
}

brainiac1530
Posts: 16
Joined: Sun Mar 02, 2014 2:32 pm

Re: Big Integers in C++ [Partially solved]

Post by brainiac1530 » Sun Mar 02, 2014 4:40 pm

GMP is the performance king. https://gmplib.org/ There are theoretically windows-friendly redistributions. If you find it impossible to install, as I did, boost includes a full-featured unlimited-precision integer. http://www.boost.org/

sam_hi
Posts: 1
Joined: Tue Jul 08, 2014 8:57 am

Re: Big Integers in C++ [Partially solved]

Post by sam_hi » Tue Jul 08, 2014 9:04 am

Here's a guide if you want to install GMP on Windows: http://www.cs.nyu.edu/exact/core/gmp/
GMP is more documented than ttmath, but it's a hassle to install for Windows-huggers like myself.

Agrentum
Posts: 10
Joined: Mon May 05, 2014 11:44 pm

Re: Big Integers in C++ [Partially solved]

Post by Agrentum » Tue Jul 15, 2014 8:54 am

If OP don't mind some questions, I would be happy to help.

Could you show example of code that throws said error? Have you tried running sample and run-testsuite programs before? How did you compile program?

Problem guess for now:
Errors like that are typical for cases where you did not link libraries correctly. Try reading Makefile or try provided Eclipse plugin.
Image - self-demoted from 357, I want to return to this score by solving everything in C/C++.

photographicus
Posts: 1
Joined: Thu Jul 02, 2015 9:39 pm

Re: Big Integers in C++ [Partially solved]

Post by photographicus » Thu Jul 02, 2015 9:40 pm


User avatar
rmacheshire
Posts: 5
Joined: Wed Nov 04, 2015 6:26 pm
Location: Portugal

Re: Big Integers in C++ [Partially solved]

Post by rmacheshire » Wed Nov 04, 2015 6:37 pm

AceInfinity wrote:Use the GMP arbitrary precision arithmetic library. It's free, and probably one of the better ones you can use.

Factorial example:

Code: Select all

void Factorial(unsigned n, mpz_t& result)
{
    mpz_set_ui(result, 1);
    for (unsigned i = 1; i <= n; ++i)
        mpz_mul_ui(result, result, i);
}
If using Windows and Visual Studio I would recommend MPIR rather than GMP (MPIR.org). This is a fork of GMP but repackaged to work with Visual Studio.

See also https://en.wikipedia.org/wiki/MPIR_%28m ... oftware%29

Post Reply