X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=boost%2Frandom%2Fdetail%2Funiform_int_float.hpp;fp=boost%2Frandom%2Fdetail%2Funiform_int_float.hpp;h=ef209157b6055b3af65f6d9c1c5c0031cfd553b6;hp=4607021e62b54ef21beb9d4b4da428bbddd2ccee;hb=2d71eb92104693ca9baa5a2e1c23eeca776d8fd3;hpb=da57529b92adbb7ae74a89861cb39fb35ac7c62d diff --git a/boost/random/detail/uniform_int_float.hpp b/boost/random/detail/uniform_int_float.hpp index 4607021..ef20915 100644 --- a/boost/random/detail/uniform_int_float.hpp +++ b/boost/random/detail/uniform_int_float.hpp @@ -1,85 +1,76 @@ /* boost random/detail/uniform_int_float.hpp header file * * Copyright Jens Maurer 2000-2001 + * Copyright Steven Watanabe 2011 * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * See http://www.boost.org for most recent version including documentation. * - * $Id: uniform_int_float.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $ + * $Id: uniform_int_float.hpp 72951 2011-07-07 04:57:37Z steven_watanabe $ * */ #ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP #define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP +#include #include +#include #include -#include +#include +#include namespace boost { namespace random { namespace detail { -template +template class uniform_int_float { public: - typedef UniformRandomNumberGenerator base_type; - typedef IntType result_type; + typedef URNG base_type; + typedef typename base_type::result_type base_result; - uniform_int_float(base_type rng, IntType min_arg = 0, IntType max_arg = 0xffffffff) - : _rng(rng), _min(min_arg), _max(max_arg) - { - init(); - } + typedef typename boost::uint_t< + (std::numeric_limits::digits < + std::numeric_limits::digits)? + std::numeric_limits::digits : + std::numeric_limits::digits + >::fast result_type; - result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } - result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } - base_type& base() { return _rng.base(); } - const base_type& base() const { return _rng.base(); } + uniform_int_float(base_type& rng) + : _rng(rng) {} - result_type operator()() - { - return static_cast(_rng() * _range) + _min; - } + static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () + { return 0; } + static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () + { + std::size_t digits = std::numeric_limits::digits; + if(detail::generator_bits::value() < digits) { + digits = detail::generator_bits::value(); + } + return (result_type(2) << (digits - 1)) - 1; + } + base_type& base() { return _rng; } + const base_type& base() const { return _rng; } -#ifndef BOOST_RANDOM_NO_STREAM_OPERATORS - template - friend std::basic_ostream& - operator<<(std::basic_ostream& os, const uniform_int_float& ud) - { - os << ud._min << " " << ud._max; - return os; - } - - template - friend std::basic_istream& - operator>>(std::basic_istream& is, uniform_int_float& ud) - { - is >> std::ws >> ud._min >> std::ws >> ud._max; - ud.init(); - return is; - } -#endif + result_type operator()() + { + base_result range = static_cast((max)())+1; + return static_cast(_rng() * range); + } private: - void init() - { - _range = static_cast(_max-_min)+1; - } - - typedef typename base_type::result_type base_result; - uniform_01 _rng; - result_type _min, _max; - base_result _range; + base_type& _rng; }; - } // namespace detail } // namespace random } // namespace boost +#include + #endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP