COIN-OR::LEMON - Graph Library

Changeset 2386:81b47fc5c444 in lemon-0.x for lemon/random.h


Ignore:
Timestamp:
03/02/07 19:04:28 (17 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3217
Message:

Hard Warning checking

  • based on the remark of the ZIB user
  • we do not use -Winline
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/random.h

    r2380 r2386  
    122122      static const int shift = 156;
    123123
    124       static const Word mul = (Word)0x5851F42Du << 32 | (Word)0x4C957F2Du;
    125       static const Word arrayInit = (Word)0x00000000u << 32 |(Word)0x012BD6AAu;
    126       static const Word arrayMul1 = (Word)0x369DEA0Fu << 32 |(Word)0x31A53F85u;
    127       static const Word arrayMul2 = (Word)0x27BB2EE6u << 32 |(Word)0x87B0B0FDu;
    128 
    129       static const Word mask = (Word)0xB5026F5Au << 32 | (Word)0xA96619E9u;
    130       static const Word loMask = ((Word)1u << 31) - 1;
     124      static const Word mul = Word(0x5851F42Du) << 32 | Word(0x4C957F2Du);
     125      static const Word arrayInit = Word(0x00000000u) << 32 |Word(0x012BD6AAu);
     126      static const Word arrayMul1 = Word(0x369DEA0Fu) << 32 |Word(0x31A53F85u);
     127      static const Word arrayMul2 = Word(0x27BB2EE6u) << 32 |Word(0x87B0B0FDu);
     128
     129      static const Word mask = Word(0xB5026F5Au) << 32 | Word(0xA96619E9u);
     130      static const Word loMask = (Word(1u) << 31) - 1;
    131131      static const Word hiMask = ~loMask;
    132132
    133133      static Word tempering(Word rnd) {
    134         rnd ^= (rnd >> 29) & ((Word)0x55555555u << 32 | (Word)0x55555555u);
    135         rnd ^= (rnd << 17) & ((Word)0x71D67FFFu << 32 | (Word)0xEDA60000u);
    136         rnd ^= (rnd << 37) & ((Word)0xFFF7EEE0u << 32 | (Word)0x00000000u);
     134        rnd ^= (rnd >> 29) & (Word(0x55555555u) << 32 | Word(0x55555555u));
     135        rnd ^= (rnd << 17) & (Word(0x71D67FFFu) << 32 | Word(0xEDA60000u));
     136        rnd ^= (rnd << 37) & (Word(0xFFF7EEE0u) << 32 | Word(0x00000000u));
    137137        rnd ^= (rnd >> 43);
    138138        return rnd;
     
    217217        }
    218218       
    219         state[length - 1] = (Word)1 << (bits - 1);
     219        state[length - 1] = Word(1) << (bits - 1);
    220220      }
    221221     
     
    274274      static Result mask(const Result& result) {
    275275        return Masker<Result, (shift + 1) / 2>::
    276           mask((Result)(result | (result >> shift)));
     276          mask(static_cast<Result>(result | (result >> shift)));
    277277      }
    278278    };
     
    281281    struct Masker<Result, 1> {
    282282      static Result mask(const Result& result) {
    283         return (Result)(result | (result >> 1));
     283        return static_cast<Result>(result | (result >> 1));
    284284      }
    285285    };
     
    292292   
    293293      static Result convert(RandomCore<Word>& rnd) {
    294         return (Result)(rnd() >> (bits - rest)) << shift;
     294        return static_cast<Result>(rnd() >> (bits - rest)) << shift;
    295295      }
    296296     
     
    302302
    303303      static Result convert(RandomCore<Word>& rnd) {
    304         return ((Result)rnd() << shift) |
     304        return (static_cast<Result>(rnd()) << shift) |
    305305          IntConversion<Result, Word, rest - bits, shift + bits>::convert(rnd);
    306306      }
     
    313313    struct Mapping {
    314314      static Result map(RandomCore<Word>& rnd, const Result& bound) {
    315         Word max = (Word)(bound - 1);
     315        Word max = Word(bound - 1);
    316316        Result mask = Masker<Result>::mask(bound - 1);
    317317        Result num;
     
    326326    struct Mapping<Result, Word, false> {
    327327      static Result map(RandomCore<Word>& rnd, const Result& bound) {
    328         Word max = (Word)(bound - 1);
     328        Word max = Word(bound - 1);
    329329        Word mask = Masker<Word, (std::numeric_limits<Result>::digits + 1) / 2>
    330330          ::mask(max);
     
    342342        Result res = ShiftMultiplier<Result, exp / 2>::multiplier();
    343343        res *= res;
    344         if ((exp & 1) == 1) res *= (Result)2.0;
     344        if ((exp & 1) == 1) res *= static_cast<Result>(2.0);
    345345        return res;
    346346      }
     
    352352        Result res = ShiftMultiplier<Result, exp / 2>::multiplier();
    353353        res *= res;
    354         if ((exp & 1) == 1) res *= (Result)0.5;
     354        if ((exp & 1) == 1) res *= static_cast<Result>(0.5);
    355355        return res;
    356356      }
     
    360360    struct ShiftMultiplier<Result, 0, true> {
    361361      static const Result multiplier() {
    362         return (Result)1.0;
     362        return static_cast<Result>(1.0);
    363363      }
    364364    };
     
    367367    struct ShiftMultiplier<Result, -20, true> {
    368368      static const Result multiplier() {
    369         return (Result)(1.0/1048576.0);
     369        return static_cast<Result>(1.0/1048576.0);
    370370      }
    371371    };
     
    374374    struct ShiftMultiplier<Result, -32, true> {
    375375      static const Result multiplier() {
    376         return (Result)(1.0/424967296.0);
     376        return static_cast<Result>(1.0/424967296.0);
    377377      }
    378378    };
     
    381381    struct ShiftMultiplier<Result, -53, true> {
    382382      static const Result multiplier() {
    383         return (Result)(1.0/9007199254740992.0);
     383        return static_cast<Result>(1.0/9007199254740992.0);
    384384      }
    385385    };
     
    388388    struct ShiftMultiplier<Result, -64, true> {
    389389      static const Result multiplier() {
    390         return (Result)(1.0/18446744073709551616.0);
     390        return static_cast<Result>(1.0/18446744073709551616.0);
    391391      }
    392392    };
     
    407407      static Result convert(RandomCore<Word>& rnd) {
    408408        return Shifting<Result, - shift - rest>::
    409           shift((Result)(rnd() >> (bits - rest)));
     409          shift(static_cast<Result>(rnd() >> (bits - rest)));
    410410      }
    411411    };
     
    416416
    417417      static Result convert(RandomCore<Word>& rnd) {
    418         return Shifting<Result, - shift - bits>::shift((Result)rnd()) +
    419           RealConversion<Result, Word, rest-bits, shift + bits>::convert(rnd);
     418        return Shifting<Result, - shift - bits>::
     419          shift(static_cast<Result>(rnd())) +
     420          RealConversion<Result, Word, rest-bits, shift + bits>::
     421          convert(rnd);
    420422      }
    421423    };
     
    428430        std::vector<Word> ws;
    429431        for (Iterator it = begin; it != end; ++it) {
    430           ws.push_back((Word)*it);
     432          ws.push_back(Word(*it));
    431433        }
    432434        rnd.initState(ws.begin(), ws.end());
Note: See TracChangeset for help on using the changeset viewer.