From 18fe275e6e8ba312315ad11015edccf3eb0fbbf2 Mon Sep 17 00:00:00 2001
From: Tor Lillqvist <tml@iki.fi>
Date: Mon, 14 Apr 2014 12:30:31 +0200
Subject: [PATCH 1/2] random: fix GCC -Wshadow warnings
Signed-off-by: Michael Stahl <mstahl@redhat.com>
---
 include/boost/random/binomial_distribution.hpp | 36 +++++++++++++-------------
 include/boost/random/shuffle_order.hpp         |  4 +--
 include/boost/random/subtract_with_carry.hpp   | 20 +++++++-------
 3 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/include/boost/random/binomial_distribution.hpp b/include/boost/random/binomial_distribution.hpp
index 8c880e8..8612eca 100644
      
        
          
        
        
          
            | a | b | private: | 
        
        
          
            | 272 | 272 | using std::sqrt; | 
          
            | 273 | 273 | using std::pow; | 
          
            | 274 | 274 |  | 
        
        
          
            | 275 |  | RealType p = (0.5 < _p)? (1 - _p) : _p; | 
          
            | 276 |  | IntType t = _t; | 
          
            |  | 275 | RealType p_lcl = (0.5 < _p)? (1 - _p) : _p; | 
          
            |  | 276 | IntType t_lcl = _t; | 
        
        
          
            | 277 | 277 |  | 
        
        
          
            | 278 |  | m = static_cast<IntType>((t +1)*p); | 
          
            |  | 278 | m = static_cast<IntType>((t_lcl+1)*p_lcl); | 
        
        
          
            | 279 | 279 |  | 
          
            | 280 | 280 | if(use_inversion()) { | 
        
        
          
            | 281 |  | q_n = pow((1 - p ), static_cast<RealType>(t)); | 
          
            |  | 281 | q_n = pow((1 - p_lcl), static_cast<RealType>(t_lcl)); | 
        
        
          
            | 282 | 282 | } else { | 
        
        
          
            | 283 |  | btrd.r = p /(1-p); | 
          
            | 284 |  | btrd.nr = (t +1)*btrd.r; | 
          
            | 285 |  | btrd.npq = t *p*(1-p); | 
          
            |  | 283 | btrd.r = p_lcl/(1-p_lcl); | 
          
            |  | 284 | btrd.nr = (t_lcl+1)*btrd.r; | 
          
            |  | 285 | btrd.npq = t_lcl*p_lcl*(1-p_lcl); | 
        
        
          
            | 286 | 286 | RealType sqrt_npq = sqrt(btrd.npq); | 
          
            | 287 | 287 | btrd.b = 1.15 + 2.53 * sqrt_npq; | 
        
        
          
            | 288 |  | btrd.a = -0.0873 + 0.0248*btrd.b + 0.01*p ; | 
          
            | 289 |  | btrd.c = t *p+ 0.5; | 
          
            |  | 288 | btrd.a = -0.0873 + 0.0248*btrd.b + 0.01*p_lcl; | 
          
            |  | 289 | btrd.c = t_lcl*p_lcl + 0.5; | 
        
        
          
            | 290 | 290 | btrd.alpha = (2.83 + 5.1/btrd.b) * sqrt_npq; | 
          
            | 291 | 291 | btrd.v_r = 0.92 - 4.2/btrd.b; | 
          
            | 292 | 292 | btrd.u_rv_r = 0.86*btrd.v_r; | 
        
        
          
            | … | … | private: | 
        
        
          
            | 304 | 304 | RealType u; | 
          
            | 305 | 305 | RealType v = uniform_01<RealType>()(urng); | 
          
            | 306 | 306 | if(v <= btrd.u_rv_r) { | 
        
        
          
            | 307 |  | RealType u = v/btrd.v_r - 0.43; | 
          
            |  | 307 | RealType u_lcl = v/btrd.v_r - 0.43; | 
        
        
          
            | 308 | 308 | return static_cast<IntType>(floor( | 
        
        
          
            | 309 |  | (2*btrd.a/(0.5 - abs(u )) + btrd.b)*u+ btrd.c)); | 
          
            |  | 309 | (2*btrd.a/(0.5 - abs(u_lcl)) + btrd.b)*u_lcl + btrd.c)); | 
        
        
          
            | 310 | 310 | } | 
          
            | 311 | 311 |  | 
          
            | 312 | 312 | if(v >= btrd.v_r) { | 
        
        
          
            | … | … | private: | 
        
        
          
            | 344 | 344 | v = log(v); | 
          
            | 345 | 345 | RealType rho = | 
          
            | 346 | 346 | (km/btrd.npq)*(((km/3. + 0.625)*km + 1./6)/btrd.npq + 0.5); | 
        
        
          
            | 347 |  | RealType t = -km*km/(2*btrd.npq); | 
          
            | 348 |  | if(v < t - rho) return k; | 
          
            | 349 |  | if(v > t + rho) continue; | 
          
            |  | 347 | RealType t_lcl = -km*km/(2*btrd.npq); | 
          
            |  | 348 | if(v < t_lcl - rho) return k; | 
          
            |  | 349 | if(v > t_lcl + rho) continue; | 
        
        
          
            | 350 | 350 |  | 
          
            | 351 | 351 | IntType nm = _t - m + 1; | 
          
            | 352 | 352 | RealType h = (m + 0.5)*log((m + 1)/(btrd.r*nm)) | 
        
        
          
            | … | … | private: | 
        
        
          
            | 367 | 367 | } | 
          
            | 368 | 368 |  | 
          
            | 369 | 369 | template<class URNG> | 
        
        
          
            | 370 |  | IntType invert(IntType t , RealType p, URNG& urng) const | 
          
            |  | 370 | IntType invert(IntType t_arg, RealType p_arg, URNG& urng) const | 
        
        
          
            | 371 | 371 | { | 
        
        
          
            | 372 |  | RealType q = 1 - p ; | 
          
            | 373 |  | RealType s = p / q; | 
          
            | 374 |  | RealType a = (t + 1) * s; | 
          
            |  | 372 | RealType q = 1 - p_arg; | 
          
            |  | 373 | RealType s = p_arg / q; | 
          
            |  | 374 | RealType a = (t_arg + 1) * s; | 
        
        
          
            | 375 | 375 | RealType r = q_n; | 
          
            | 376 | 376 | RealType u = uniform_01<RealType>()(urng); | 
          
            | 377 | 377 | IntType x = 0; | 
        
      
    
    
      
      diff --git a/include/boost/random/shuffle_order.hpp b/include/boost/random/shuffle_order.hpp
index 646c09b..e775dd0 100644
      
        
          
        
        
          
            | a | b | public: | 
        
        
          
            | 200 | 200 | } | 
          
            | 201 | 201 |  | 
          
            | 202 | 202 | /** Returns true if the two generators will produce identical sequences. */ | 
        
        
          
            | 203 |  | BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(shuffle_order_engine, x, y ) | 
          
            | 204 |  | { return x._rng == y ._rng && x.y == y.y && std::equal(x.v, x.v+k, y.v); } | 
          
            |  | 203 | BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(shuffle_order_engine, x, y_arg) | 
          
            |  | 204 | { return x._rng == y_arg._rng && x.y == y_arg.y && std::equal(x.v, x.v+k, y_arg.v); } | 
        
        
          
            | 205 | 205 | /** Returns true if the two generators will produce different sequences. */ | 
          
            | 206 | 206 | BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(shuffle_order_engine) | 
          
            | 207 | 207 |  | 
        
      
    
    
      
      diff --git a/include/boost/random/subtract_with_carry.hpp b/include/boost/random/subtract_with_carry.hpp
index dc430e6..927ee72 100644
      
        
          
        
        
          
            | a | b | private: | 
        
        
          
            | 268 | 268 |  | 
          
            | 269 | 269 | friend struct detail::subtract_with_carry_discard; | 
          
            | 270 | 270 |  | 
        
        
          
            | 271 |  | IntType do_update(std::size_t current, std::size_t short_index, IntType carry ) | 
          
            |  | 271 | IntType do_update(std::size_t current, std::size_t short_index, IntType carry_arg) | 
        
        
          
            | 272 | 272 | { | 
          
            | 273 | 273 | IntType delta; | 
        
        
          
            | 274 |  | IntType temp = x[current] + carry ; | 
          
            |  | 274 | IntType temp = x[current] + carry_arg; | 
        
        
          
            | 275 | 275 | if (x[short_index] >= temp) { | 
          
            | 276 | 276 | // x(n) >= 0 | 
          
            | 277 | 277 | delta =  x[short_index] - temp; | 
        
        
          
            | 278 |  | carry = 0; | 
          
            |  | 278 | carry_arg = 0; | 
        
        
          
            | 279 | 279 | } else { | 
          
            | 280 | 280 | // x(n) < 0 | 
          
            | 281 | 281 | delta = modulus - temp + x[short_index]; | 
        
        
          
            | 282 |  | carry = 1; | 
          
            |  | 282 | carry_arg = 1; | 
        
        
          
            | 283 | 283 | } | 
          
            | 284 | 284 | x[current] = delta; | 
        
        
          
            | 285 |  | return carry ; | 
          
            |  | 285 | return carry_arg; | 
        
        
          
            | 286 | 286 | } | 
          
            | 287 | 287 | /// \endcond | 
          
            | 288 | 288 |  | 
        
        
          
            | … | … | private: | 
        
        
          
            | 498 | 498 |  | 
          
            | 499 | 499 | friend struct detail::subtract_with_carry_discard; | 
          
            | 500 | 500 |  | 
        
        
          
            | 501 |  | RealType do_update(std::size_t current, std::size_t short_index, RealType carry ) | 
          
            |  | 501 | RealType do_update(std::size_t current, std::size_t short_index, RealType carry_arg) | 
        
        
          
            | 502 | 502 | { | 
        
        
          
            | 503 |  | RealType delta = x[short_index] - x[current] - carry ; | 
          
            |  | 503 | RealType delta = x[short_index] - x[current] - carry_arg; | 
        
        
          
            | 504 | 504 | if(delta < 0) { | 
          
            | 505 | 505 | delta += RealType(1); | 
        
        
          
            | 506 |  | carry = RealType(1)/_modulus; | 
          
            |  | 506 | carry_arg = RealType(1)/_modulus; | 
        
        
          
            | 507 | 507 | } else { | 
        
        
          
            | 508 |  | carry = 0; | 
          
            |  | 508 | carry_arg = 0; | 
        
        
          
            | 509 | 509 | } | 
          
            | 510 | 510 | x[current] = delta; | 
        
        
          
            | 511 |  | return carry ; | 
          
            |  | 511 | return carry_arg; | 
        
        
          
            | 512 | 512 | } | 
          
            | 513 | 513 | /// \endcond | 
          
            | 514 | 514 | std::size_t k; |