Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53802 - in trunk: boost/random libs/random
From: steven_at_[hidden]
Date: 2009-06-11 20:24:09


Author: steven_watanabe
Date: 2009-06-11 20:24:09 EDT (Thu, 11 Jun 2009)
New Revision: 53802
URL: http://svn.boost.org/trac/boost/changeset/53802

Log:
misc assertions/tests
Text files modified:
   trunk/boost/random/uniform_real.hpp | 8 +++++---
   trunk/libs/random/instantiate.cpp | 2 ++
   2 files changed, 7 insertions(+), 3 deletions(-)

Modified: trunk/boost/random/uniform_real.hpp
==============================================================================
--- trunk/boost/random/uniform_real.hpp (original)
+++ trunk/boost/random/uniform_real.hpp 2009-06-11 20:24:09 EDT (Thu, 11 Jun 2009)
@@ -52,9 +52,11 @@
 
   template<class Engine>
   result_type operator()(Engine& eng) {
- return static_cast<result_type>(eng() - eng.min BOOST_PREVENT_MACRO_SUBSTITUTION())
- / static_cast<result_type>(eng.max BOOST_PREVENT_MACRO_SUBSTITUTION() - eng.min BOOST_PREVENT_MACRO_SUBSTITUTION())
- * (_max - _min) + _min;
+ result_type numerator = static_cast<result_type>(eng() - eng.min BOOST_PREVENT_MACRO_SUBSTITUTION());
+ result_type divisor = static_cast<result_type>(eng.max BOOST_PREVENT_MACRO_SUBSTITUTION() - eng.min BOOST_PREVENT_MACRO_SUBSTITUTION());
+ assert(divisor > 0);
+ assert(numerator >= 0 && numerator <= divisor);
+ return numerator / divisor * (_max - _min) + _min;
   }
 
 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS

Modified: trunk/libs/random/instantiate.cpp
==============================================================================
--- trunk/libs/random/instantiate.cpp (original)
+++ trunk/libs/random/instantiate.cpp 2009-06-11 20:24:09 EDT (Thu, 11 Jun 2009)
@@ -56,6 +56,8 @@
   // this keeps a reference to urng
   boost::variate_generator<URNG&, Dist> genref(urng, dist);
 
+ BOOST_CHECK(gen.engine() == genref.engine());
+
 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   // and here is a pointer to (a copy of) the urng
   URNG copy = urng;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk