From fa185c7fbdb86960c0f75ba6e4f84452eca9af62 Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Wed, 23 Sep 2015 15:34:49 -0500 Subject: [PATCH] BUG: Guarantee non-zero is 1 for switch statements In numpy/core/src/npymath/npy_math.c.src there is a state machine sequence that assumes signbit returns either a 1 or 0. However, all the online documentation states that it will return either a 0 or a nonzero value, which seems to be determined by the OS. These changes allow the code to work with a zero or a nonzero value. --- numpy/core/src/npymath/npy_math.c.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/core/src/npymath/npy_math.c.src b/numpy/core/src/npymath/npy_math.c.src index b7f28bb39be0..7f62810d5b7b 100644 --- a/numpy/core/src/npymath/npy_math.c.src +++ b/numpy/core/src/npymath/npy_math.c.src @@ -130,7 +130,7 @@ double npy_atan2(double y, double x) return npy_atan(y); } - m = 2 * npy_signbit(x) + npy_signbit(y); + m = 2 * (npy_signbit((x)) != 0) + (npy_signbit((y)) != 0); if (y == 0.0) { switch(m) { case 0: