I'm trying to implement George Marsaglia's Complementary Multiply-With-Carry algorithm in C. It seems to work great under Win7 64 bit and Linux 32 bit, but seems to behave strangely under Win 7 32 bit. The random number it returns is 32 bit, but there's a temporary value used internally that's supposed to be 64 bits, and it's declared:
我正在尝试在c中实现George Marsaglia的互补的带进位的多路多路算法,它在Win7 64位和Linux 32位下似乎运行得很好,但是在Win7 32位下却表现得很奇怪。它返回的随机数是32位,但是内部有一个临时值应该是64位,它声明为:
unsigned long long t;
I suspect this might be the cause of the misbehaviour, so my question is:
我怀疑这可能是不当行为的原因,所以我的问题是:
Is the type "long long" 64 bits? Is it supported in 32 bit Windows?
“长”型是64位吗?它在32位窗口中支持吗?
2 个解决方案
#1
5
The type long long
is guaranteed to be at least 64 bits (although the guarantee is formally in the form of the range of values it must be able to represent).
类型long保证至少为64位(尽管该保证的形式是其必须能够表示的值范围)。
The following is in §5.2.4.2.1 of the C99 standard (link to draft):
下面是在§5.2.4.2.1 C99标准(草案)链接:
— maximum value for an object of type
unsigned long long int
-无符号长整数类型对象的最大值
ULLONG_MAX 18446744073709551615 // 2**64 − 1
ULLONG_MAX 64 / / 2 * * 18446744073709551615−1
#2
7
If your compiler has stdint.h
I would suggest using uint64_t
instead.
如果你的编译器有stdint。我建议改用uint64_t。
#1
5
The type long long
is guaranteed to be at least 64 bits (although the guarantee is formally in the form of the range of values it must be able to represent).
类型long保证至少为64位(尽管该保证的形式是其必须能够表示的值范围)。
The following is in §5.2.4.2.1 of the C99 standard (link to draft):
下面是在§5.2.4.2.1 C99标准(草案)链接:
— maximum value for an object of type
unsigned long long int
-无符号长整数类型对象的最大值
ULLONG_MAX 18446744073709551615 // 2**64 − 1
ULLONG_MAX 64 / / 2 * * 18446744073709551615−1
#2
7
If your compiler has stdint.h
I would suggest using uint64_t
instead.
如果你的编译器有stdint。我建议改用uint64_t。