1 /* boost random/uniform_real.hpp header file
3 * Copyright Jens Maurer 2000-2001
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org for most recent version including documentation.
13 * 2001-04-08 added min<max assertion (N. Becker)
14 * 2001-02-18 moved to individual header files
17 #ifndef BOOST_RANDOM_UNIFORM_REAL_HPP
18 #define BOOST_RANDOM_UNIFORM_REAL_HPP
22 #include <boost/config.hpp>
23 #include <boost/limits.hpp>
24 #include <boost/static_assert.hpp>
25 #include <boost/random/detail/config.hpp>
29 // uniform distribution on a real range
30 template<class RealType
= double>
34 typedef RealType input_type
;
35 typedef RealType result_type
;
37 explicit uniform_real(RealType min_arg
= RealType(0),
38 RealType max_arg
= RealType(1))
39 : _min(min_arg
), _max(max_arg
)
41 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
42 BOOST_STATIC_ASSERT(!std::numeric_limits
<RealType
>::is_integer
);
44 assert(min_arg
<= max_arg
);
47 // compiler-generated copy ctor and assignment operator are fine
49 result_type min
BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min
; }
50 result_type max
BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max
; }
53 template<class Engine
>
54 result_type
operator()(Engine
& eng
) {
55 return static_cast<result_type
>(eng() - eng
.min
BOOST_PREVENT_MACRO_SUBSTITUTION())
56 / static_cast<result_type
>(eng
.max
BOOST_PREVENT_MACRO_SUBSTITUTION() - eng
.min
BOOST_PREVENT_MACRO_SUBSTITUTION())
57 * (_max
- _min
) + _min
;
60 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
61 template<class CharT
, class Traits
>
62 friend std::basic_ostream
<CharT
,Traits
>&
63 operator<<(std::basic_ostream
<CharT
,Traits
>& os
, const uniform_real
& ud
)
65 os
<< ud
._min
<< " " << ud
._max
;
69 template<class CharT
, class Traits
>
70 friend std::basic_istream
<CharT
,Traits
>&
71 operator>>(std::basic_istream
<CharT
,Traits
>& is
, uniform_real
& ud
)
73 is
>> std::ws
>> ud
._min
>> std::ws
>> ud
._max
;
84 #endif // BOOST_RANDOM_UNIFORM_REAL_HPP