random_int: Fix power of two check.

(x & ~x) is always 0.
((x & (~x + 1)) != x) works.
((x & (x - 1)) != 0) works too.
This commit is contained in:
Lauri Kenttä 2015-05-10 13:40:29 +03:00 committed by Nikita Popov
parent 8c8889e7d4
commit cf7e5357a4

View File

@ -182,7 +182,7 @@ PHP_FUNCTION(random_int)
umax++; umax++;
/* Powers of two are not biased */ /* Powers of two are not biased */
if ((umax & ~umax) != umax) { if ((umax & (umax - 1)) != 0) {
/* Ceiling under which ZEND_LONG_MAX % max == 0 */ /* Ceiling under which ZEND_LONG_MAX % max == 0 */
zend_ulong limit = ZEND_ULONG_MAX - (ZEND_ULONG_MAX % umax) - 1; zend_ulong limit = ZEND_ULONG_MAX - (ZEND_ULONG_MAX % umax) - 1;