Skip to content

Commit 767ccd8

Browse files
authored
Merge pull request numpy#28116 from WarrenWeckesser/fix-zipf-compiler-warning
MAINT: random: Explicitly cast RAND_INT_MAX to double to avoid compiler warning
2 parents 93b6447 + 51a21be commit 767ccd8

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

numpy/random/_common.pyx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ cdef int check_constraint(double val, object name, constraint_type cons) except
467467
# Note: Assume value is integral (double of LONG_MAX should work out)
468468
if val < 0:
469469
raise ValueError(name + " < 0")
470-
elif val > LONG_MAX:
470+
elif val > <double> LONG_MAX:
471471
raise ValueError(
472472
name + " is out of bounds for long, consider using "
473473
"the new generator API for 64bit integers.")
@@ -918,31 +918,33 @@ cdef object disc(void *func, void *state, object size, object lock,
918918
else:
919919
raise NotImplementedError("No vector path available")
920920

921+
# At this point, we know is_scalar is True.
922+
921923
if narg_double > 0:
922924
_da = PyFloat_AsDouble(a)
923-
if a_constraint != CONS_NONE and is_scalar:
925+
if a_constraint != CONS_NONE:
924926
check_constraint(_da, a_name, a_constraint)
925927

926928
if narg_double > 1:
927929
_db = PyFloat_AsDouble(b)
928-
if b_constraint != CONS_NONE and is_scalar:
930+
if b_constraint != CONS_NONE:
929931
check_constraint(_db, b_name, b_constraint)
930932
elif narg_int64 == 1:
931933
_ib = <int64_t>b
932-
if b_constraint != CONS_NONE and is_scalar:
934+
if b_constraint != CONS_NONE:
933935
check_constraint(<double>_ib, b_name, b_constraint)
934936
else:
935937
if narg_int64 > 0:
936938
_ia = <int64_t>a
937-
if a_constraint != CONS_NONE and is_scalar:
939+
if a_constraint != CONS_NONE:
938940
check_constraint(<double>_ia, a_name, a_constraint)
939941
if narg_int64 > 1:
940942
_ib = <int64_t>b
941-
if b_constraint != CONS_NONE and is_scalar:
943+
if b_constraint != CONS_NONE:
942944
check_constraint(<double>_ib, b_name, b_constraint)
943945
if narg_int64 > 2:
944946
_ic = <int64_t>c
945-
if c_constraint != CONS_NONE and is_scalar:
947+
if c_constraint != CONS_NONE:
946948
check_constraint(<double>_ic, c_name, c_constraint)
947949

948950
if size is None:

numpy/random/src/distributions/distributions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ RAND_INT_TYPE random_zipf(bitgen_t *bitgen_state, double a) {
10231023
* Values below Umin would result in X being rejected because it is too
10241024
* large, so there is no point in including them in the distribution of U.
10251025
*/
1026-
Umin = pow(RAND_INT_MAX, -am1);
1026+
Umin = pow((double) RAND_INT_MAX, -am1);
10271027
while (1) {
10281028
double U01, T, U, V, X;
10291029

0 commit comments

Comments
 (0)