Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:09

0001 /* boost random/detail/uniform_int_float.hpp header file
0002  *
0003  * Copyright Jens Maurer 2000-2001
0004  * Copyright Steven Watanabe 2011
0005  * Distributed under the Boost Software License, Version 1.0. (See
0006  * accompanying file LICENSE_1_0.txt or copy at
0007  * http://www.boost.org/LICENSE_1_0.txt)
0008  *
0009  * See http://www.boost.org for most recent version including documentation.
0010  *
0011  * $Id$
0012  *
0013  */
0014 
0015 #ifndef BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
0016 #define BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
0017 
0018 #include <boost/limits.hpp>
0019 #include <boost/config.hpp>
0020 #include <boost/integer.hpp>
0021 #include <boost/random/detail/config.hpp>
0022 #include <boost/random/detail/generator_bits.hpp>
0023 
0024 #include <boost/random/detail/disable_warnings.hpp>
0025 
0026 namespace boost {
0027 namespace random {
0028 namespace detail {
0029 
0030 template<class URNG>
0031 class uniform_int_float
0032 {
0033 public:
0034     typedef URNG base_type;
0035     typedef typename base_type::result_type base_result;
0036 
0037     typedef typename boost::uint_t<
0038         (std::numeric_limits<boost::uintmax_t>::digits <
0039             std::numeric_limits<base_result>::digits)?
0040         std::numeric_limits<boost::uintmax_t>::digits :
0041         std::numeric_limits<base_result>::digits
0042     >::fast result_type;
0043 
0044     uniform_int_float(base_type& rng)
0045       : _rng(rng) {}
0046 
0047     static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
0048     { return 0; }
0049     static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
0050     {
0051         std::size_t digits = std::numeric_limits<result_type>::digits;
0052         if(detail::generator_bits<URNG>::value() < digits) {
0053             digits = detail::generator_bits<URNG>::value();
0054         }
0055         return (result_type(2) << (digits - 1)) - 1;
0056     }
0057     base_type& base() { return _rng; }
0058     const base_type& base() const { return _rng; }
0059 
0060     result_type operator()()
0061     {
0062         base_result range = static_cast<base_result>((max)())+1;
0063         return static_cast<result_type>(_rng() * range);
0064     }
0065 
0066 private:
0067     base_type& _rng;
0068 };
0069 
0070 } // namespace detail
0071 } // namespace random
0072 } // namespace boost
0073 
0074 #include <boost/random/detail/enable_warnings.hpp>
0075 
0076 #endif // BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP