• About

j.matthew.turner

~ Director. Videographer. Editor. Geek.

Tag Archives: boost

Setting up Boost C++ Libraries for Large Integers in Code::Blocks on OS X

21 Tuesday Oct 2014

Posted by jmatthewturner in C++, Geekery, Mac, Programming

≈ 1 Comment

Tags

BigInts, boost, c++, code::blocks, mac, programming, projecteuler

Having trouble getting integers larger than 64 bits to work in C++? So was I. Here’s how I fixed it:

  1. You’ll want to use the data type cpp_int provided by Boost C++ Libraries.
    1. Go here and download the zip: http://sourceforge.net/projects/boost/files/boost/1.56.0/
    2. Unzip into a forever home. (You’ll probably want this again sometime, so don’t just stick it in your project folder and forget about it.)
  2. Code::BlocksCode::Blocks needs some priming before you can use Boost:
    1. With your project open, choose: Project->Build Options….
    2. Select the Search Directories tab.
    3. Use the Add button at the bottom to add the path to your new Boost directory. This needs to be the directory that was created when you extracted the zip file. (In my case, I added /Users/jmatthewturner/C++/Boost/boost_1_56_0.)
  3. And your project file needs some special code:
    1. Add an #include for the cpp_int.hpp file that is inside boost/multiprecision/. Mine looks like this:
      #include "/Users/jmatthewturner/C++/Boost/boost_1_56_0/boost/multiprecision/cpp_int.hpp"

Now you can use the data type cpp_int, which is an arbitrarily large integer, limited only by the memory available on your machine. It is part of the namespace boost::multiprecision, so always refer to it like this:

boost::multiprecision::cpp_int myBigInteger;

or define a namespace to make your life a little easier:

using namespace std;
namespace mp = boost::multiprecision;
mp::cpp_int myBigInteger;
mp::cpp_int myFunction(mp::cpp_int x);

…etc, etc. And that should do it. I used cpp_int to help solve Project Euler #20; I’ll post the source code when I get around to writing up the problem.

Recent Posts

  • Premiere Pro’s Project Manager Can’t Handle Double-Nests
  • Encrypt Your Dropbox Files with VeraCrypt
  • Mortal Kombat and Enter the Dragon Are the Same Movie
  • 16×9 Linux VMs Inside VirtualBox
  • Adobe Releases Creative Cloud 2015

Categories

  • Advertising
  • Apple
  • C++
  • Creative Cloud
  • Editing
  • Film
  • Geekery
  • Linux
  • Mac
  • Marketing
  • Organization
  • Panasonic
  • Premiere Pro
  • Programming
  • Project Euler
  • Python
  • SEO
  • Shooting
  • Uncategorized
  • Yosemite

Recent Comments

Miquel Parejo on Premiere Pro’s Project M…
Meny on Premiere Pro’s Project M…
dnn on Project Euler #6: Sum Square…
jmatthewturner on Premiere Pro Audio Synching Pi…
Kalyan on Premiere Pro Audio Synching Pi…

Archives

  • June 2017
  • July 2016
  • July 2015
  • June 2015
  • April 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • May 2014
  • September 2013

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Create a free website or blog at WordPress.com.

Cancel

 
Loading Comments...
Comment
    ×
    Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
    To find out more, including how to control cookies, see here: Cookie Policy