25 Aralık 2017 Pazartesi

multiprecision mpfr_float Sınıfı

Giriş
Tanımlaması şöyle
typedef number<mpfr_float_backend<50> >    mpfr_float_50;
typedef number<mpfr_float_backend<100> >   mpfr_float_100;
typedef number<mpfr_float_backend<500> >   mpfr_float_500;
typedef number<mpfr_float_backend<1000> >  mpfr_float_1000;
typedef number<mpfr_float_backend<0> >     mpfr_float;
Örnek
Şöyle yaparız.
#include <iostream>

#include <boost/multiprecision/mpfr.hpp>

using boost::multiprecision::number;
using boost::multiprecision::backends::mpfr_float_backend;

template < unsigned size >
void print(number<mpfr_float_backend<size>> const &num)
{
    std::cout << "mpfr_float_" << size << ": " << num << "\n";
}


int main()
{
    using namespace boost::multiprecision;
    mpfr_float_50 a = 1;
    mpfr_float_100 b = 2;
    mpfr_float_500 c = 3;
    double d = 4;

    print(a);
    print(b);
    print(c);
  //print(d); // BOOM!
}

Hiç yorum yok:

Yorum Gönder