I'm trying to generate random numbers from normal distribution using boost's multiprecision. I can generate random numbers from uniform distributions, but when I tried to generate from standard normal, it reports an error. Here is the code:
(follows from Examples from boost, change mpz_int to cpp_int, and mpf_float_50 to cpp_dec_float_50)
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/random.hpp>
#include <boost/multiprecision/number.hpp>
int main()
{
using namespace boost::multiprecision;
using namespace boost::random;
uniform_01<cpp_dec_float_50> uf;
normal_distribution<cpp_dec_float_50> n01(0.0, 1.0);
independent_bits_engine<mt19937, 50L*1000L/301L, cpp_int> gen;
std::cout << std::setprecision(50);
for(unsigned i = 0; i < 1; ++i) {
std::cout << uf(gen) << std::endl;
std::cout << n01(gen) << std::endl;
}
return 0;
}
However, I can generate random numbers from uniform distributions, but when I tried to generate from standard normal, it shows:
g++ -I/~/boost/boost_1_58_0 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test_boost.d" -MT"test_boost.d" -o "test_boost.o" "../test_boost.cpp"
boost/boost_1_58_0/boost/random/detail/uniform_int_float.hpp:63: error: invalid static_cast from type ‘boost::multiprecision::detail::expression >, (boost::multiprecision::expression_template_option)1u>, boost::multiprecision::number >, (boost::multiprecision::expression_template_option)1u>, void, void>’ to type ‘long unsigned int’
I use gcc version 4.4.7, and 64 bit linux system. Thank you so much.
(I also tried to use boost's example to generate random numbers, but I have a lot of errors simply by include , such as: error: ‘struct boost::multiprecision::backends::gmp_int’ has no member named ‘data’)
Aucun commentaire:
Enregistrer un commentaire