ttmath

Hi, I'm a beginner in c++ and I need a library that can handle really large integers. I saw on Internet that the best library to perform this task is ttmath. I´ve downloaded it, but i´ve no idea how to install it. Anyone can help me? I use windows vista and mingw.I really need help.
Thanks in advance.
Perhaps Boost.Multiprecision merits consideration. (cpp_int is header-only.)
http://www.boost.org/doc/libs/1_54_0/libs/multiprecision/doc/html/index.html

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

int main()
{
    using bigint = boost::multiprecision::cpp_int ;

    bigint i( "1234567890987654321" ) ;

    std::cout << i * 12345 << '\n' ;
}

http://coliru.stacked-crooked.com/a/0b514c46a94e62b8
closed account (4jzvC542)
mingw.........? you are using command line version
then it is going to be difficult as you have to configure them not just copy paste

[link]http://stackoverflow.com/questions/2164001/installing-c-c-libraries-on-windows/2164091#2164091[/link]

don't know how to install ttmath myself
but i suggest you check out full fledge IDEs like
1) MS Visual C++ 2010/1012 Express
2) Code::Block or Code::lite

i have heard they offer good support for libraries and other stuff
ultimately google is best companion ....... just Google it
i use codeblocks as an ide. What compiler do you thinks i should use, so that the installation of libraries would be easier?
JLBorges, I followed your advice and I downloaded Boost.Multiprecision, but i've no idea on how to install it. Could you help me, please?
Have you downloaded the boost libraries?

For instance boost_1_54_0.zip or one of the other files listed in http://sourceforge.net/projects/boost/files/boost/1.54.0/
I only had a quick glance at ttmath, but it looks like you just need to configure the compiler so that it knows which directory to look in when trying to locate the file which you are including.
In code::blocks, menu:
 
Settings->compiler->search directories

add the path to the ttmath files.

Then, in your code, you simply need to put #include "ttmath.h" at the start of your code. If that compiles, you can go ahead and use the library to do something useful - start with the samples provided in the ttmath documentation.
Last edited on
yes, i've downloaded "boost_1_54_0.zip" and extracted it. Now, how can i install it? I'm really a beginner. I use windows vista, code blocks as an ide and gnu gcc as a compiler.
Thanks in advance.
You now need to add the directory containing boost to the compiler search path for include files.

For instance, if you have extracted boost into "C:\local\share"
the boost files would be in subdirectories under "C:\local\share\boost\boost_1_54_0"

To add this directory via a compiler option: -I C:\local\share\boost\boost_1_54_0

Or from within the CodeBlocks IDE
Menu => Settings => Compiler... => Search Directories => Compiler => Add
specify: C:\local\share\boost\boost_1_54_0
By the way, it is sometimes worth to select different instrument for specific task. If you need this only for occasion, it would be much better to switch temporarily to Python or Java which have support for large numbers packed in.

At the same time if you need some simple calculations on big numbers, you can easily write necessary procedures on arrays from scratch.
I've done as you said. I added C:\Users\utilizador\Desktop\boost_1_54_0 to the compiler search path from within the CodeBlocks IDE and I also added C:\Users\utilizador\Desktop\boost_1_54_0 as a link library, so that I don´t get an error message stating "undefined reference" when I try compile a sample of boost multiprecision.
But then, when I try to compile, I get an error message saying:
"cannot find C:\Users\utilizador\Desktop\boost_1_54_0: Permission denied".
Do you know what's wrong?
Thanks in advance.
> I also added C:\Users\utilizador\Desktop\boost_1_54_0 as a link library

Please remove that.

C:\Users\utilizador\Desktop\boost_1_54_0 is a directory, not a library.


> so that I don´t get an error message stating "undefined reference" when I try compile a sample of boost

boost::multiprecision::cpp_int is header-only.
Only the headers are required; there is no library to link to.
I never managed to compile a sample of boost multiprecision. Every time I try it, I get lots of errors.
For example, when I tried to compile the example you showed I got 4 errors about "bigint".
One of them was for example:"'bigint' has not been declared".
Do you know why this happens?
> Do you know why this happens?

Perhaps, you haven't enabled C++11.


Are you able to compile this cleanly?

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

int main()
{
    // using bigint = boost::multiprecision::cpp_int ;

    boost::multiprecision::cpp_int i( "1234567890987654321" ) ;

    std::cout << i * 12345 << '\n' ;
}
Last edited on
yes
When you run the program, do you get the expected output?
(15240740614242592592745)
yes
Great.

If you would like to use a type alias (say bigint) everyehere, you could do one of two things:

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

int main()
{
    typedef boost::multiprecision::cpp_int bigint ;

    bigint i( "1234567890987654321" ) ;

    std::cout << i * 12345 << '\n' ;
}


Or (recommended) the original code with C++11 enabled:

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

int main()
{
    using bigint = boost::multiprecision::cpp_int ;

    bigint i( "1234567890987654321" ) ;

    std::cout << i * 12345 << '\n' ;
}


In CodeBlocks,
Menu => Settings => Compiler... Compiler settings =>Compiler Flags

check -std=c++11

While you are at it, also check -Wall, -Wextra and -pedantic-errors
Topic archived. No new replies allowed.