#144 msvc unsigned/signed problem in random.h


Msvc fails to compile IT++ 3.10.8 "out of the box" because of an unsigned/signed warning being treated as an error with the project settings provided.

The problem is due to the mixing of signed and unsigned integers in the function twist. By proper typecasting, the problem disappears.

I changed line 202 in random.h


{ return m ^ (mixBits(s0,s1)>>1) ^ (-loBit(s1) & 0x9908b0dfU); }


{ return m ^ (mixBits(s0,s1)>>1) ^ (static_cast<unsigned int="">(-static_cast<int>(loBit(s1))) & 0x9908b0dfU); }

Maybe there is a better way to do the same thing, but this solution works fine.


  • Adam Piątyszek

    Adam Piątyszek - 2007-01-16

    Logged In: YES
    Originator: NO

    Thanks for your report Tomas. I have already contacted the author of this code (this is a third party code included in IT++) to comment on this problem.


  • Adam Piątyszek

    Adam Piątyszek - 2007-01-17

    Logged In: YES
    Originator: NO

    This bug is now fixed in the repository sources. Therefore I am closing this bug report.

    For your convenience, here is the fixed twist() function code:

    unsigned int twist( const unsigned int& m, const unsigned int& s0,
            const unsigned int& s1 ) const
    { return m ^ (mixBits(s0,s1)>>1) ^ (loBit(s1) ? 0x9908b0dfU : 0U); }

    This implementation is almost identical to the macro implementation from original C sources by Takuji Nishimura and Makoto Matsumoto:

    #define MATRIX_A 0x9908b0dfUL / constant vector a /
    #define UMASK 0x80000000UL / most significant w-r bits /
    #define LMASK 0x7fffffffUL / least significant r bits /
    #define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) )
    #define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks