当我编译mt19937ar.c,一个非常标准的随机数生成器时,我不断从一些我需要的代码中获取问题。不能解决“警告:从'int'转换为'long unsigned int'”
在函数 'init_genrand':
警告:转换从 'INT' '长UNSIGNED INT' 可以改变结果的
/* Period parameters */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
static unsigned long mt[N]; /* the array for the state vector */
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
/* initializes mt[N] with a seed */
void init_genrand(unsigned long s)
{
mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
mt[mti] =
(1812433253UL * (mt[mti-1]^(mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
mt[mti] &= 0xffffffffUL;
/* for >32 bit machines */
}
}
具体的符号,误差与
mt[mti] =
(1812433253UL * (mt[mti-1]^(mt[mti-1] >> 30)) + mti);
我试过通过
mt[mti] = (long unsigned int)
(1812433253UL * (mt[mti-1]^(mt[mti-1] >> 30)) + mti);
这真的没有什么意义,但我只是想做点什么。这个代码是从1997年开始的 - 现在有人会抓住它并修复它。我该如何解决这个问题?或让我的编译器停止对它的哭泣?
怎么样'30UL'晋升为
unsigned long
? –@SouravGhosh什么是'30UL'? – 8protons
使整数常量被视为'unsigned long'而不是默认'int'。 –