Opened 8 years ago

Last modified 7 years ago

#10364 new Bugs

Release 1.56 broke random::uniform_real_distribution

Reported by: mouse008@… Owned by: No-Maintainer
Milestone: To Be Determined Component: random
Version: Boost 1.56.0 Severity: Regression
Keywords: Cc:

Description

Multiprecision random uniform_real_distribution<mpf_float_50> stopped working correctly with 1.56. It worked fine with 1.55, and the attached code is one of the examples that Boost documentation shows for this class.

I have this problem manifesting on Mac OS X 10.9.4 under all the compilers I got: native clang from Xcode-5.1.1, clang++-mp-3.4 (macports clang v3.4.2), g++ v4.8.3.

Attaching the complete source file that demonstrates the problem (35 lines of code), and the compiler output (748 lines of text).

Attachments (3)

boost-r3.cpp (865 bytes ) - added by mouse008@… 8 years ago.
Source code that demonstrates the problem
b-r3.out (196.4 KB ) - added by mouse008@… 8 years ago.
Compiler (clang-3.4.2 from macports) output demonstrating the problem. Same code compiles and runs fine with same compilers with boost_1_55_0.
b-r6b.out (206.0 KB ) - added by Mouse <mouse008@…> 7 years ago.
Output of failed compilation of b-r6b.cpp

Download all attachments as: .zip

Change History (17)

by mouse008@…, 8 years ago

Attachment: boost-r3.cpp added

Source code that demonstrates the problem

by mouse008@…, 8 years ago

Attachment: b-r3.out added

Compiler (clang-3.4.2 from macports) output demonstrating the problem. Same code compiles and runs fine with same compilers with boost_1_55_0.

comment:2 by mouse008@…, 7 years ago

Not sure - I'm now on clang-3.7 and boost_1.59, with this problem persisting. When is this commit likely to end up in a release?

comment:3 by mouse008@…, 7 years ago

In fact, re-checking my 1.5 years old code, I see that a lot more of stuff that used GMP multi precision library and/or boost_random is broken now (under the current released clang, and the current released boost-1.59). Will post here soon.

by Mouse <mouse008@…>, 7 years ago

Attachment: b-r6b.out added

Output of failed compilation of b-r6b.cpp

comment:4 by Mouse <mouse008@…>, 7 years ago

Further checking shows that uniform_real_distribution<> uc(-20.0, 20.0); works (compiles and runs fine). uniform_real_distribution<mpf_float_50> ur(-20.0, 20.0); fails to compile (see attached output of compile attempt: b-r6b.out).

This compiles and runs OK:

#include <iostream>
#include <boost/multiprecision/gmp.hpp>
#include <boost/multiprecision/random.hpp>

using namespace boost::multiprecision;
using namespace boost::random;

int main() {

	unsigned long long myseed = 0x12345670;
	mt19937 rgen(myseed);
	uniform_real_distribution<> uc(-20.0, 20.0);

	std::cout << std::hex
	// << std::showbase
	;

	//
	// Generate some values:
	//
	std::cout << std::setprecision(50);
	for(unsigned i = 0; i < 20; ++i)
		std::cout << std::setw(2) << (i+1) << ": "
			  << std::setw(20)
			  << uc(rgen)
			  << std::endl;
	std::cout << std::endl;
}

giving this output:

$ ./b-r6a
 1: 17.07083447836339473724365234375
 2: 18.59527722932398319244384765625
 3: 17.2086485661566257476806640625
 4: -7.10314041934907436370849609375
 5: 12.02050872147083282470703125
 6: 16.396274752914905548095703125
 7: 18.85700456798076629638671875
 8: 0.078481473028659820556640625
 9: 4.03215981088578701019287109375
 a: 3.56800344772636890411376953125
 b: 4.79332183487713336944580078125
 c: 0.429534278810024261474609375
 d: 13.35449189879000186920166015625
 e: -6.27208642661571502685546875
 f: 13.10226154513657093048095703125
10: -8.06778541766107082366943359375
11: 6.47328031249344348907470703125
12: -9.097188748419284820556640625
13: 16.7489224486052989959716796875
14: 18.96312631666660308837890625

This does not compile (see the attached output):

#include <iostream>
#include <boost/multiprecision/gmp.hpp>
#include <boost/multiprecision/random.hpp>

using namespace boost::multiprecision;
using namespace boost::random;

int main() {

	unsigned long long myseed = 0x12345670;
	mt19937 rgen(myseed);
	independent_bits_engine<mt19937, 100, mpf_float_50> gen3(rgen);
	uniform_real_distribution<mpf_float_50> ur(-20.0, 20.0);

	std::cout << std::hex
	// << std::showbase
	;

	//
	// Generate some values:
	//
	std::cout << std::setprecision(50);
	for(unsigned i = 0; i < 20; ++i)
		std::cout << std::setw(2) << (i+1) << ": "
			  << std::setw(20)
			  << ur(gen3) << "  "
			  << ur(rgen)
			  << std::endl;
	std::cout << std::endl;
}

Unfortunately I cannot test the proposed commit because I'm not building Boost myself (any more). I have to wait until the fix percolates down to the distributions, and Macports picks it up. :-(

comment:5 by Mouse <mouse008@…>, 7 years ago

Note that the above code is copied almost verbatim from the Boost documentation: http://www.boost.org/doc/libs/1_59_0/libs/multiprecision/doc/html/boost_multiprecision/tut/random.html.

(Copying really verbatim produces the same result.)

comment:6 by Steven Watanabe, 7 years ago

The fix would be in 1.60.

comment:7 by Mouse <mouse008@…>, 7 years ago

The fix would be in 1.60.

Thank you - I'm glad to hear that.

comment:7 by Mouse <mouse008@…>, 7 years ago

The fix would be in 1.60.

Thank you - I'm glad to hear that.

comment:8 by Mouse <mouse008@…>, 7 years ago

It still doesn't look fully fixed:

#include <iostream>
#include <boost/multiprecision/gmp.hpp>
#include <boost/multiprecision/random.hpp>

using namespace boost::multiprecision;
using namespace boost::random;

int main() {

	unsigned long long myseed = 0x12345670;
	mt19937 rgen(myseed);
	independent_bits_engine<mt19937, 100, mpf_float_50> gen3(rgen);
	uniform_real_distribution<mpf_float_50> ur(-20.0, 20.0);

	std::cout << std::hex
	// << std::showbase
	;

	//
	// Generate some values:
	//
	std::cout << std::setprecision(50);
	for(unsigned i = 0; i < 20; ++i)
		std::cout << std::setw(2) << (i+1) << ": "
			  << std::setw(20)
			  << ur(gen3) << "  "
			  << ur(rgen)
			  << std::endl;
	std::cout << std::endl;
}
$ clang++ -o b-r6b -I ~/src/boost_1_60_0/include -I/opt/local/include b-r6b.cpp -L ~/src/boost_1_60_0/lib -lboost_system -lboost_filesystem -lboost_random -L/opt/local/lib -lgmp -lrdrand
In file included from b-r6b.cpp:3:
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/random.hpp:12:10: warning:
      NOTE: Use of this header (boost/multiprecision/random.hpp) is deprecated:
      please use the random number library headers directly. [-W#pragma-messages]
# pragma message("NOTE: Use of this header (boost/multiprecision/random.hpp...
         ^
In file included from b-r6b.cpp:3:
In file included from /Users/uri/src/boost_1_60_0/include/boost/multiprecision/random.hpp:16:
In file included from /Users/uri/src/boost_1_60_0/include/boost/random.hpp:38:
/Users/uri/src/boost_1_60_0/include/boost/random/independent_bits.hpp:167:20: error:
      invalid operands to binary expression ('result_type' (aka
      'boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on>') and 'std::size_t'
      (aka 'unsigned long'))
            S = (S << w0) + (u & y0_mask);
                 ~ ^  ~~
/Users/uri/src/boost_1_60_0/include/boost/random/uniform_real_distribution.hpp:40:48: note:
      in instantiation of member function
      'boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >::operator()'
      requested here
        result_type numerator = static_cast<T>(eng() - (eng.min)());
                                               ^
/Users/uri/src/boost_1_60_0/include/boost/random/uniform_real_distribution.hpp:72:12: note:
      in instantiation of function template specialization
      'boost::random::detail::generate_uniform_real<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >' requested here
    return generate_uniform_real(eng, min_value, max_value,
           ^
/Users/uri/src/boost_1_60_0/include/boost/random/uniform_real_distribution.hpp:193:22: note:
      in instantiation of function template specialization
      'boost::random::detail::generate_uniform_real<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >' requested here
    { return detail::generate_uniform_real(eng, _min, _max); }
                     ^
b-r6b.cpp:26:11: note: in instantiation of function template specialization
      'boost::random::uniform_real_distribution<boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on>
      >::operator()<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> > >' requested here
                          << ur(gen3) << "  "
                               ^
/Users/uri/src/boost_1_60_0/include/boost/optional/optional.hpp:1274:1: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
operator<<(std::basic_ostream<CharType, CharTrait>& os, optional_detail::opt...
^
/Users/uri/src/boost_1_60_0/include/boost/smart_ptr/shared_ptr.hpp:897:64: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (s...
                                                               ^
/Users/uri/src/boost_1_60_0/include/boost/format/format_class.hpp:118:9: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
        operator<<( std::basic_ostream<Ch2, Tr2> & ,
        ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/no_et_ops.hpp:274:4: note:
      candidate template ignored: could not match 0 against 1
   operator << (const number<B, et_off>& a, const I& b)
   ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/et_ops.hpp:599:4: note:
      candidate template ignored: substitution failure [with B =
      boost::multiprecision::backends::gmp_float<50>, I = unsigned long]: no type
      named 'type' in 'boost::enable_if_c<false,
      boost::multiprecision::detail::expression<boost::multiprecision::detail::shift_left,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on>, unsigned long,
      void, void> >'
   operator << (const number<B, et_on>& a, const I& b)
   ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/et_ops.hpp:606:7: note:
      candidate template ignored: could not match 'expression' against 'number'
      operator << (const detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& a...
      ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/number.hpp:1685:22: note:
      candidate template ignored: could not match 'number<type-parameter-0-0,
      ExpressionTemplates>' against 'unsigned long'
inline std::ostream& operator << (std::ostream& os, const number<Backend, Ex...
                     ^
In file included from b-r6b.cpp:3:
In file included from /Users/uri/src/boost_1_60_0/include/boost/multiprecision/random.hpp:16:
In file included from /Users/uri/src/boost_1_60_0/include/boost/random.hpp:38:
/Users/uri/src/boost_1_60_0/include/boost/random/independent_bits.hpp:174:20: error:
      invalid operands to binary expression ('result_type' (aka
      'boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on>') and
      'unsigned long')
            S = (S << (w0 + 1)) + (u & y1_mask);
                 ~ ^  ~~~~~~~~
/Users/uri/src/boost_1_60_0/include/boost/optional/optional.hpp:1274:1: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
operator<<(std::basic_ostream<CharType, CharTrait>& os, optional_detail::opt...
^
/Users/uri/src/boost_1_60_0/include/boost/smart_ptr/shared_ptr.hpp:897:64: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (s...
                                                               ^
/Users/uri/src/boost_1_60_0/include/boost/format/format_class.hpp:118:9: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
        operator<<( std::basic_ostream<Ch2, Tr2> & ,
        ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/no_et_ops.hpp:274:4: note:
      candidate template ignored: could not match 0 against 1
   operator << (const number<B, et_off>& a, const I& b)
   ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/et_ops.hpp:599:4: note:
      candidate template ignored: substitution failure [with B =
      boost::multiprecision::backends::gmp_float<50>, I = unsigned long]: no type
      named 'type' in 'boost::enable_if_c<false,
      boost::multiprecision::detail::expression<boost::multiprecision::detail::shift_left,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on>, unsigned long,
      void, void> >'
   operator << (const number<B, et_on>& a, const I& b)
   ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/et_ops.hpp:606:7: note:
      candidate template ignored: could not match 'expression' against 'number'
      operator << (const detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& a...
      ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/number.hpp:1685:22: note:
      candidate template ignored: could not match 'number<type-parameter-0-0,
      ExpressionTemplates>' against 'unsigned long'
inline std::ostream& operator << (std::ostream& os, const number<Backend, Ex...
                     ^
In file included from b-r6b.cpp:3:
In file included from /Users/uri/src/boost_1_60_0/include/boost/multiprecision/random.hpp:16:
In file included from /Users/uri/src/boost_1_60_0/include/boost/random.hpp:38:
/Users/uri/src/boost_1_60_0/include/boost/random/independent_bits.hpp:240:81: error:
      invalid operands to binary expression
      ('boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on>' and
      'unsigned long')
  ...< std::numeric_limits<UIntType>::digits ? UIntType((UIntType(1) << w) - 1) ...
                                                         ~~~~~~~~~~~ ^  ~
/Users/uri/src/boost_1_60_0/include/boost/random/independent_bits.hpp:59:14: note:
      in instantiation of member function
      'boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >::max_imp'
      requested here
    { return max_imp(boost::is_integral<UIntType>()); }
             ^
/Users/uri/src/boost_1_60_0/include/boost/random/uniform_real_distribution.hpp:41:51: note:
      in instantiation of member function
      'boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >::max' requested
      here
        result_type divisor = static_cast<T>((eng.max)() - (eng.min)());
                                                  ^
/Users/uri/src/boost_1_60_0/include/boost/random/uniform_real_distribution.hpp:72:12: note:
      in instantiation of function template specialization
      'boost::random::detail::generate_uniform_real<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >' requested here
    return generate_uniform_real(eng, min_value, max_value,
           ^
/Users/uri/src/boost_1_60_0/include/boost/random/uniform_real_distribution.hpp:193:22: note:
      in instantiation of function template specialization
      'boost::random::detail::generate_uniform_real<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> >' requested here
    { return detail::generate_uniform_real(eng, _min, _max); }
                     ^
b-r6b.cpp:26:11: note: in instantiation of function template specialization
      'boost::random::uniform_real_distribution<boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on>
      >::operator()<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 100,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on> > >' requested here
                          << ur(gen3) << "  "
                               ^
/Users/uri/src/boost_1_60_0/include/boost/optional/optional.hpp:1274:1: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
operator<<(std::basic_ostream<CharType, CharTrait>& os, optional_detail::opt...
^
/Users/uri/src/boost_1_60_0/include/boost/smart_ptr/shared_ptr.hpp:897:64: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (s...
                                                               ^
/Users/uri/src/boost_1_60_0/include/boost/format/format_class.hpp:118:9: note:
      candidate template ignored: could not match 'basic_ostream' against 'number'
        operator<<( std::basic_ostream<Ch2, Tr2> & ,
        ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/no_et_ops.hpp:274:4: note:
      candidate template ignored: could not match 0 against 1
   operator << (const number<B, et_off>& a, const I& b)
   ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/et_ops.hpp:599:4: note:
      candidate template ignored: substitution failure [with B =
      boost::multiprecision::backends::gmp_float<50>, I = unsigned long]: no type
      named 'type' in 'boost::enable_if_c<false,
      boost::multiprecision::detail::expression<boost::multiprecision::detail::shift_left,
      boost::multiprecision::number<boost::multiprecision::backends::gmp_float<50>,
      boost::multiprecision::expression_template_option::et_on>, unsigned long,
      void, void> >'
   operator << (const number<B, et_on>& a, const I& b)
   ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/detail/et_ops.hpp:606:7: note:
      candidate template ignored: could not match 'expression' against 'number'
      operator << (const detail::expression<tag, Arg1, Arg2, Arg3, Arg4>& a...
      ^
/Users/uri/src/boost_1_60_0/include/boost/multiprecision/number.hpp:1685:22: note:
      candidate template ignored: could not match 'number<type-parameter-0-0,
      ExpressionTemplates>' against 'unsigned long'
inline std::ostream& operator << (std::ostream& os, const number<Backend, Ex...
                     ^
1 warning and 3 errors generated.
$

comment:9 by Steven Watanabe, 7 years ago

The example code is wrong (It's been updated in the docs for 1.60). independent_bits_engine produces integers and must not be used with floating point types.

comment:10 by Mouse <mouse008@…>, 7 years ago

The example code is wrong (It's been updated in the docs for 1.60).

Here's what I used to guide me:

Boost-1.54 tutorial: http://www.boost.org/doc/libs/1_54_0/libs/multiprecision/doc/html/boost_multiprecision/tut/random.html

Now the Boost-1.60 tutorial: http://www.boost.org/doc/libs/1_60_0/libs/multiprecision/doc/html/boost_multiprecision/tut/random.html suggests using cpp_bin_float_50 instead of mpf_float_50, and independent_bits_engine. But it is unclear in this example how to specify a certain number of digits or bits for uniform_real_distribution<cpp_bin_float_50> that uses independent_bits_engine<nt19937, ...>. Perhaps you could point me at a description/tutorial?

Thanks!

P.S. I tried to replicate the last example from the above 1.60 tutorial, and here's the result. Am I doing something obviously wrong? This is with Boost-1.59.

#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/random.hpp>

int main()
{
   using namespace boost::multiprecision;
   using namespace boost::random;
   //
   // Generate some distruted values:
   //
   uniform_real_distribution<cpp_bin_float_50> ur(-20, 20);
   gamma_distribution<cpp_bin_float_50> gd(20);
   independent_bits_engine<mt19937, std::numeric_limits<cpp_bin_float_50>::digits, cpp_int> gen;
   //
   // Generate some values:
   //
   std::cout << std::setprecision(50);
   std::cout << "uniform_real_distribution<cpp_bin_float_50> ur(-20, 20):" << std::endl;
   for(unsigned i = 0; i < 20; ++i)
     std::cout << (i+1) << ": " << ur(gen) << std::endl;
   std::cout << std::endl;
   std::cout << "gamma_distribution<cpp_bin_float_50> gd(20):" << std::endl;
   for(unsigned i = 0; i < 20; ++i)
     std::cout << (i+1) << ": " << gd(gen) << std::endl;
   std::cout << std::endl;
   return 0;
}
$ make b-r6b
clang++-mp-3.7 -maes -mpclmul -mrdrnd -msse2 -mssse3 -msse4.2 -mtune=native -Os -Ofast -std=c++11 -fPIC -m64 -msse4.2 -I/opt/local/include -Wno-comment -c b-r6b.cpp
In file included from b-r6b.cpp:1:
In file included from /opt/local/include/boost/multiprecision/cpp_bin_float.hpp:9:
In file included from /opt/local/include/boost/multiprecision/cpp_int.hpp:12:
In file included from /opt/local/include/boost/multiprecision/number.hpp:22:
In file included from /opt/local/include/boost/multiprecision/detail/generic_interconvert.hpp:9:
In file included from /opt/local/include/boost/multiprecision/detail/default_ops.hpp:10:
In file included from /opt/local/include/boost/multiprecision/detail/number_base.hpp:17:
In file included from /opt/local/include/boost/lexical_cast.hpp:32:
In file included from /opt/local/include/boost/lexical_cast/try_lexical_convert.hpp:35:
In file included from /opt/local/include/boost/lexical_cast/detail/converter_lexical.hpp:54:
In file included from /opt/local/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:77:
/opt/local/include/boost/integer.hpp:138:6: error: static_assert failed "No suitable
      unsigned integer type with the requested number of bits is available."
     BOOST_STATIC_ASSERT_MSG(Bits <= (int)(sizeof(boost::uintmax_t) * CHAR_BIT),
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/static_assert.hpp:31:45: note: expanded from macro
      'BOOST_STATIC_ASSERT_MSG'
#     define BOOST_STATIC_ASSERT_MSG( ... ) static_assert(__VA_ARGS__)
                                            ^             ~~~~~~~~~~~
/opt/local/include/boost/integer/integer_mask.hpp:63:22: note: in instantiation of
      template class 'boost::uint_t<168>' requested here
    typedef typename uint_t<Bits>::least  least;
                     ^
/opt/local/include/boost/random/independent_bits.hpp:58:21: note: in instantiation
      of template class 'boost::low_bits_mask_t<168>' requested here
    { return boost::low_bits_mask_t<w>::sig_bits; }
                    ^
/opt/local/include/boost/random/uniform_real_distribution.hpp:41:51: note: in
      instantiation of member function
      'boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> >::max' requested
      here
        result_type divisor = static_cast<T>((eng.max)() - (eng.min)());
                                                  ^
/opt/local/include/boost/random/uniform_real_distribution.hpp:72:12: note: in
      instantiation of function template specialization
      'boost::random::detail::generate_uniform_real<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> >,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off> >' requested
      here
    return generate_uniform_real(eng, min_value, max_value,
           ^
/opt/local/include/boost/random/uniform_real_distribution.hpp:193:22: note: in
      instantiation of function template specialization
      'boost::random::detail::generate_uniform_real<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> >,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off> >' requested
      here
    { return detail::generate_uniform_real(eng, _min, _max); }
                     ^
b-r6b.cpp:21:38: note: in instantiation of function template specialization
      'boost::random::uniform_real_distribution<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>
      >::operator()<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> > >' requested here
     std::cout << (i+1) << ": " << ur(gen) << std::endl;
                                     ^
In file included from b-r6b.cpp:3:
In file included from /opt/local/include/boost/random.hpp:36:
In file included from /opt/local/include/boost/random/additive_combine.hpp:27:
In file included from /opt/local/include/boost/random/linear_congruential.hpp:32:
In file included from /opt/local/include/boost/random/detail/seed_impl.hpp:20:
/opt/local/include/boost/integer/integer_mask.hpp:64:36: error: no type named 'fast'
      in 'boost::uint_t<168>'
    typedef typename uint_t<Bits>::fast   fast;
            ~~~~~~~~~~~~~~~~~~~~~~~^~~~
/opt/local/include/boost/random/independent_bits.hpp:58:21: note: in instantiation
      of template class 'boost::low_bits_mask_t<168>' requested here
    { return boost::low_bits_mask_t<w>::sig_bits; }
                    ^
/opt/local/include/boost/random/uniform_real_distribution.hpp:41:51: note: in
      instantiation of member function
      'boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> >::max' requested
      here
        result_type divisor = static_cast<T>((eng.max)() - (eng.min)());
                                                  ^
/opt/local/include/boost/random/uniform_real_distribution.hpp:72:12: note: in
      instantiation of function template specialization
      'boost::random::detail::generate_uniform_real<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> >,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off> >' requested
      here
    return generate_uniform_real(eng, min_value, max_value,
           ^
/opt/local/include/boost/random/uniform_real_distribution.hpp:193:22: note: in
      instantiation of function template specialization
      'boost::random::detail::generate_uniform_real<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> >,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off> >' requested
      here
    { return detail::generate_uniform_real(eng, _min, _max); }
                     ^
b-r6b.cpp:21:38: note: in instantiation of function template specialization
      'boost::random::uniform_real_distribution<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>
      >::operator()<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> > >' requested here
     std::cout << (i+1) << ": " << ur(gen) << std::endl;
                                     ^
In file included from b-r6b.cpp:3:
In file included from /opt/local/include/boost/random.hpp:40:
In file included from /opt/local/include/boost/random/lagged_fibonacci.hpp:30:
/opt/local/include/boost/random/uniform_01.hpp:177:40: error: no type named
      'result_type' in
      'boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>'
  typedef typename traits::value_type::result_type base_result;
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/opt/local/include/boost/random/uniform_01.hpp:235:12: note: in instantiation of
      template class
      'boost::random::detail::backward_compatible_uniform_01<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>, double>'
      requested here
  : public detail::select_uniform_01<UniformRandomNumberGenerator>::BOOST_NE...
           ^
/opt/local/include/boost/random/gamma_distribution.hpp:175:42: note: in
      instantiation of template class
      'boost::random::uniform_01<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>, double>'
      requested here
                result_type y = tan(pi * uniform_01<RealType>()(eng));
                                         ^
b-r6b.cpp:25:38: note: in instantiation of function template specialization
      'boost::random::gamma_distribution<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>
      >::operator()<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> > >' requested here
     std::cout << (i+1) << ": " << gd(gen) << std::endl;
                                     ^
In file included from b-r6b.cpp:3:
In file included from /opt/local/include/boost/random.hpp:61:
In file included from /opt/local/include/boost/random/chi_squared_distribution.hpp:20:
/opt/local/include/boost/random/gamma_distribution.hpp:180:20: error: type
      'uniform_01<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off> >' does not
      provide a call operator
                if(uniform_01<RealType>()(eng) >
                   ^~~~~~~~~~~~~~~~~~~~~~
b-r6b.cpp:25:38: note: in instantiation of function template specialization
      'boost::random::gamma_distribution<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>
      >::operator()<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> > >' requested here
     std::cout << (i+1) << ": " << gd(gen) << std::endl;
                                     ^
In file included from b-r6b.cpp:3:
In file included from /opt/local/include/boost/random.hpp:61:
In file included from /opt/local/include/boost/random/chi_squared_distribution.hpp:20:
In file included from /opt/local/include/boost/random/gamma_distribution.hpp:25:
/opt/local/include/boost/random/exponential_distribution.hpp:132:42: error: type
      'uniform_01<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off> >' does not
      provide a call operator
            _lambda * log(result_type(1)-uniform_01<RealType>()(eng));
                                         ^~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/random/gamma_distribution.hpp:170:20: note: in
      instantiation of function template specialization
      'boost::random::exponential_distribution<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>
      >::operator()<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> > >' requested here
            return _exp(eng) * _beta;
                   ^
b-r6b.cpp:25:38: note: in instantiation of function template specialization
      'boost::random::gamma_distribution<boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<50,
      boost::multiprecision::backends::digit_base_type::digit_base_10, void, int, 0,
      0>, boost::multiprecision::expression_template_option::et_off>
      >::operator()<boost::random::independent_bits_engine<boost::random::mersenne_twister_engine<unsigned
      int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
      4022730752, 18, 1812433253>, 168,
      boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0,
      0, boost::multiprecision::cpp_integer_type::signed_magnitude,
      boost::multiprecision::cpp_int_check_type::unchecked,
      std::__1::allocator<unsigned long long> >,
      boost::multiprecision::expression_template_option::et_on> > >' requested here
     std::cout << (i+1) << ": " << gd(gen) << std::endl;
                                     ^
5 errors generated.
make: *** [b-r6b.o] Error 1

comment:11 by Mouse <mouse008@…>, 7 years ago

Adding #include <boost/multiprecision/random.hpp> to the above source code fixed the problem. ???

in reply to:  10 comment:12 by Steven Watanabe, 7 years ago

Replying to Mouse <mouse008@…>:

Now the Boost-1.60 tutorial: http://www.boost.org/doc/libs/1_60_0/libs/multiprecision/doc/html/boost_multiprecision/tut/random.html suggests using cpp_bin_float_50 instead of mpf_float_50, and independent_bits_engine. But it is unclear in this example how to specify a certain number of digits or bits for uniform_real_distribution<cpp_bin_float_50> that uses independent_bits_engine<nt19937, ...>. Perhaps you could point me at a description/tutorial?

uniform_real_distribution uses the same number of bits as the underlying generator. Just set the number of bits of independent_bits_engine to what you need.

P.S. I tried to replicate the last example from the above 1.60 tutorial, and here's the result. Am I doing something obviously wrong? This is with Boost-1.59.

You're using 1.59. The fixes to Boost.Random to support multiprecision weren't merged until 1.60.

comment:13 by Mouse <mouse008@…>, 7 years ago

Got it, thanks!

I guess we can close this ticket.

Note: See TracTickets for help on using tickets.