Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68823 - trunk/boost/random
From: steven_at_[hidden]
Date: 2011-02-12 23:05:28


Author: steven_watanabe
Date: 2011-02-12 23:05:26 EST (Sat, 12 Feb 2011)
New Revision: 68823
URL: http://svn.boost.org/trac/boost/changeset/68823

Log:
Use unsigned types everywhere to be compatible with the standard, which is more restrictive in this respect.
Text files modified:
   trunk/boost/random/additive_combine.hpp | 12 ++++++------
   trunk/boost/random/inversive_congruential.hpp | 2 +-
   trunk/boost/random/linear_congruential.hpp | 18 +++++++++---------
   3 files changed, 16 insertions(+), 16 deletions(-)

Modified: trunk/boost/random/additive_combine.hpp
==============================================================================
--- trunk/boost/random/additive_combine.hpp (original)
+++ trunk/boost/random/additive_combine.hpp 2011-02-12 23:05:26 EST (Sat, 12 Feb 2011)
@@ -184,10 +184,10 @@
 
     /** Returns the next value of the generator. */
     result_type operator()() {
- result_type z = _mlcg1() - _mlcg2();
- if(z < 1)
- z += MLCG1::modulus-1;
- return z;
+ result_type val1 = _mlcg1();
+ result_type val2 = _mlcg2();
+ if(val2 < val1) return val1 - val2;
+ else return val1 - val2 + MLCG1::modulus - 1;
     }
   
     /** Fills a range with random values */
@@ -276,8 +276,8 @@
  * @endblockquote
  */
 typedef additive_combine_engine<
- linear_congruential_engine<int32_t, 40014, 0, 2147483563>,
- linear_congruential_engine<int32_t, 40692, 0, 2147483399>
+ linear_congruential_engine<uint32_t, 40014, 0, 2147483563>,
+ linear_congruential_engine<uint32_t, 40692, 0, 2147483399>
> ecuyer1988;
 
 } // namespace random

Modified: trunk/boost/random/inversive_congruential.hpp
==============================================================================
--- trunk/boost/random/inversive_congruential.hpp (original)
+++ trunk/boost/random/inversive_congruential.hpp 2011-02-12 23:05:26 EST (Sat, 12 Feb 2011)
@@ -260,7 +260,7 @@
  * (editors), 1995, pp. 255-262. ftp://random.mat.sbg.ac.at/pub/data/wsc95.ps
  * @endblockquote
  */
-typedef inversive_congruential_engine<int32_t, 9102, 2147483647-36884165,
+typedef inversive_congruential_engine<uint32_t, 9102, 2147483647-36884165,
   2147483647> hellekalek1995;
 
 } // namespace random

Modified: trunk/boost/random/linear_congruential.hpp
==============================================================================
--- trunk/boost/random/linear_congruential.hpp (original)
+++ trunk/boost/random/linear_congruential.hpp 2011-02-12 23:05:26 EST (Sat, 12 Feb 2011)
@@ -299,7 +299,7 @@
  * the ACM, Vol. 31, No. 10, October 1988, pp. 1192-1201
  * @endblockquote
  */
-typedef linear_congruential_engine<int32_t, 16807, 0, 2147483647> minstd_rand0;
+typedef linear_congruential_engine<uint32_t, 16807, 0, 2147483647> minstd_rand0;
 
 /** The specialization \minstd_rand was suggested in
  *
@@ -309,7 +309,7 @@
  * the ACM, Vol. 31, No. 10, October 1988, pp. 1192-1201
  * @endblockquote
  */
-typedef linear_congruential_engine<int32_t, 48271, 0, 2147483647> minstd_rand;
+typedef linear_congruential_engine<uint32_t, 48271, 0, 2147483647> minstd_rand;
 
 
 #if !defined(BOOST_NO_INT64_T) && !defined(BOOST_NO_INTEGRAL_INT64_T)
@@ -326,21 +326,21 @@
 class rand48
 {
 public:
- typedef int32_t result_type;
+ typedef uint32_t result_type;
 
     BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
     /**
      * Returns the smallest value that the generator can produce
      */
- static int32_t min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
+ static uint32_t min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
     /**
      * Returns the largest value that the generator can produce
      */
- static int32_t max BOOST_PREVENT_MACRO_SUBSTITUTION ()
- { return (std::numeric_limits<int32_t>::max)(); }
+ static uint32_t max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return 0x7FFFFFFF; }
   
     /** Seeds the generator with the default seed. */
- rand48() : lcf(cnv(static_cast<int32_t>(1))) {}
+ rand48() : lcf(cnv(static_cast<uint32_t>(1))) {}
     /**
      * If T is an integral type smaller than int64_t, constructs
      * a \rand48 generator with x(0) := (x0 << 16) | 0x330e. Otherwise
@@ -360,7 +360,7 @@
     // compiler-generated copy ctor and assignment operator are fine
 
     /** Seeds the generator with the default seed. */
- void seed() { seed(static_cast<int32_t>(1)); }
+ void seed() { seed(static_cast<uint32_t>(1)); }
     /**
      * If T is an integral type smaller than int64_t, changes
      * the current value x(n) of the generator to (x0 << 16) | 0x330e.
@@ -378,7 +378,7 @@
     template<class SeedSeq> void seed(SeedSeq& seq) { lcf.seed(cnv(seq)); }
 
     /** Returns the next value of the generator. */
- int32_t operator()() { return static_cast<int32_t>(lcf() >> 17); }
+ uint32_t operator()() { return static_cast<uint32_t>(lcf() >> 17); }
     
 #ifndef BOOST_NO_LONG_LONG
     /** Advances the state of the generator by @c z. */


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