fix doc example typo
[boost.git] / boost / random / uniform_real.hpp
blob241ad0d4f18f0bd5047fe042328f55f2a334e83e
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.
10 * $Id$
12 * Revision history
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
20 #include <cassert>
21 #include <iostream>
22 #include <boost/config.hpp>
23 #include <boost/limits.hpp>
24 #include <boost/static_assert.hpp>
25 #include <boost/random/detail/config.hpp>
27 namespace boost {
29 // uniform distribution on a real range
30 template<class RealType = double>
31 class uniform_real
33 public:
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);
43 #endif
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; }
51 void reset() { }
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;
66 return os;
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;
74 return is;
76 #endif
78 private:
79 RealType _min, _max;
82 } // namespace boost
84 #endif // BOOST_RANDOM_UNIFORM_REAL_HPP