Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2004-01-15 14:45:08


Thanks for your effort.

Reproduced the problem and fixed it as suggested.

Jens Maurer

Mario Ruetti wrote:
> I wrote a little test program to reproduce the error. myGen is a 'generator'
> which produces uint64_t sized numbers....
> This produces a floating-point exception. See the comment at the end of this
> message how to fix this bug.
>
> Mario Rütti
>
> // snipp ----
>
> #include <iostream>
> #include <cmath>
>
> #include <boost/random.hpp>
>
>
> class myGen
> {
> public:
> typedef uint64_t result_type;
> result_type min() const { return 0; }
> result_type max() const { return std::numeric_limits< myGen::result_type
>
>>::max(); }
>
> result_type operator()()
> {
> return std::numeric_limits< myGen::result_type >::max()-1;
> }
> };
>
>
> int main()
> {
> // no problem
> using boost::mt19937;
> mt19937 rng;
> boost::variate_generator< mt19937, boost::uniform_int<> > uni_rng( rng,
> boost::uniform_int<>(0,10) );
> for (int i=0;i<10;i++)
> std::cout << uni_rng() << std::endl;
>
> //problem (Gleitkomma-Ausnahme)
> myGen myrng;
> boost::variate_generator< myGen, boost::uniform_int<> > myuni_rng( myrng,
> boost::uniform_int<>(0,10) );
> for (int i=0;i<10;i++)
> std::cout << myuni_rng() << std::endl;
> }
>
> // snapp ----
>
>
> // Change in 'uniform_smallint.hpp' in
>
> // template<class IntType = int>
> // class uniform_smallint
> // {
> // .....
>
> // template<class Engine>
> // result_type operator()(Engine& eng)
> // {
> // typedef typename Engine::result_type base_result;
> // base_result _range = static_cast<base_result>(_max-_min)+1;
> // // int _factor = 1; <-- original code
> // base_result _factor = 1; <-- replacement
> // ^^^^^^^^^^^^^^^^^^^^^^^^
> // int is to small, use base_result as type for _factor
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk