8000 MAINT: random: Fix a few compiler warnings. · numpy/numpy@5b34a0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b34a0c

Browse files
MAINT: random: Fix a few compiler warnings.
Fixes: gcc: numpy/random/src/xoshiro256/xoshiro256.c numpy/random/src/xoshiro256/xoshiro256.c:39:16: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] for (i = 0; i < sizeof JUMP / sizeof *JUMP; i++) ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc: numpy/random/src/xoshiro512/xoshiro512.c numpy/random/src/xoshiro512/xoshiro512.c:43:17: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] for (i = 0; i < sizeof JUMP / sizeof *JUMP; i++) ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~ numpy/random/src/xoshiro512/xoshiro512.c:46:23: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] for (w = 0; w < sizeof s_placeholder / sizeof *s_placeholder; w++) ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc: numpy/random/src/distributions/distributions.c numpy/random/src/distributions/distributions.c:185:14: warning: comparison of integers of different signs: 'int64_t' (aka 'long long') and 'const uint64_t' (aka 'const unsigned long long') [-Wsign-compare] if (rabs < ki_double[idx]) ~~~~ ^ ~~~~~~~~~~~~~~ numpy/random/src/distributions/distributions.c:230:14: warning: comparison of integers of different signs: 'int32_t' (aka 'int') and 'const uint32_t' (aka 'const unsigned int') [-Wsign-compare] if (rabs < ki_float[idx]) ~~~~ ^ ~~~~~~~~~~~~~
1 parent e3eb398 commit 5b34a0c

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

numpy/random/src/distributions/distributions.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ float random_standard_exponential_zig_f(bitgen_t *bitgen_state) {
169169
static NPY_INLINE double next_gauss_zig(bitgen_t *bitgen_state) {
170170
uint64_t r;
171171
int sign;
172-
int64_t rabs;
172+
uint64_t rabs;
173173
int idx;
174174
double x, xx, yy;
175175
for (;;) {
@@ -178,7 +178,7 @@ static NPY_INLINE double next_gauss_zig(bitgen_t *bitgen_state) {
178178
idx = r & 0xff;
179179
r >>= 8;
180180
sign = r & 0x1;
181-
rabs = (int64_t)((r >> 1) & 0x000fffffffffffff);
181+
rabs = (r >> 1) & 0x000fffffffffffff;
182182
x = rabs * wi_double[idx];
183183
if (sign & 0x1)
184184
x = -x;
@@ -215,15 +215,15 @@ void random_gauss_zig_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) {
215215
float random_gauss_zig_f(bitgen_t *bitgen_state) {
216216
uint32_t r;
217217
int sign;
218-
int32_t rabs;
218+
uint32_t rabs;
219219
int idx;
220220
float x, xx, yy;
221221
for (;;) {
222222
/* r = n23sb8 */
223223
r = next_uint32(bitgen_state);
224224
idx = r & 0xff;
225225
sign = (r >> 8) & 0x1;
226-
rabs = (int32_t)((r >> 9) & 0x0007fffff);
226+
rabs = (r >> 9) & 0x0007fffff;
227227
x = rabs * wi_float[idx];
228228
if (sign & 0x1)
229229
x = -x;

numpy/random/src/xoshiro256/xoshiro256.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ worldwide. This software is distributed without any warranty.
66
77
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
88

9+
#include <stddef.h>
910
#include "xoshiro256.h"
1011

1112
/* This is xoshiro256** 1.0, our all-purpose, rock-solid generator. It has
@@ -29,7 +30,7 @@ extern NPY_INLINE uint32_t xoshiro256_next32(xoshiro256_state *state);
2930

3031
void xoshiro256_jump(xoshiro256_state *state)
3132
{
32-
int i, b;
33+
size_t i, b;
3334
static const uint64_t JUMP[] = {0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c};
3435

3536
uint64_t s0 = 0;

numpy/random/src/xoshiro512/xoshiro512.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ worldwide. This software is distributed without any warranty.
66
77
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
88

9+
#include <stddef.h>
910
#include "xoshiro512.h"
1011

1112
/* This is xoshiro512** 1.0, an all-purpose, rock-solid generator. It has
@@ -32,7 +33,7 @@ static uint64_t s_placeholder[8];
3233

3334
void xoshiro512_jump(xoshiro512_state *state) {
3435

35-
int i, b, w;
36+
size_t i, b, w;
3637
static const uint64_t JUMP[] = {0x33ed89b6e7a353f9, 0x760083d7955323be,
3738
0x2837f2fbb5f22fae, 0x4b8c5674d309511c,
3839
0xb11ac47a7ba28c25, 0xf1be7667092bcc1c,

0 commit comments

Comments
 (0)
0