1

I've been using Visual Studio Code Runner to compile C++ projects without a problem, but now I need to use the GMP backend with Boost Multiprecision Library.

As I showed in a different question, I already have working code that relies only on Boost Multiprecision Library. What I'm trying to do is to use GMP's high precision floats instead of the ones that come with Boost. Like the following:

#include <iostream>
#include <boost/math/distributions/negative_binomial.hpp>
#include <boost/multiprecision/gmp.hpp>

using namespace std;
using namespace boost;

typedef boost::multiprecision::number<boost::multiprecision::gmp_float<50>> myPrecision;
// typedef boost::multiprecision::mpf_float_50 myPrecision; // this also raises the errors

template <class T1, class T2>
myPrecision negbinPDF(T1 passed_val, T2 passed_par1, T2 passed_par2)
{
    myPrecision val = myPrecision(passed_val);
    myPrecision par1 =  myPrecision(passed_par1);
    myPrecision par2 = myPrecision(passed_par2);

    return math::pdf(math::negative_binomial_distribution<myPrecision>(par1, par2), val);
};

int main() {
    auto p = negbinPDF(1.23456789012345678901234567890, 8.0, 0.25);
    cout << "The PDF is: " << p << endl;
}

When running the above code, many errors are raised (see here), starting with some undefined references. Hence my question: How can I link to GMP using Visual Studio Code's Code Runner (in Linux)?

karel
  • 5,489
  • 46
  • 45
  • 50
blipblop
  • 155
  • 1
  • 12

0 Answers0