summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/common/npy_longdouble.c3
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src5
-rw-r--r--numpy/core/tests/test_longdouble.py14
3 files changed, 17 insertions, 5 deletions
diff --git a/numpy/core/src/common/npy_longdouble.c b/numpy/core/src/common/npy_longdouble.c
index 4e7541f8f..88c8616fd 100644
--- a/numpy/core/src/common/npy_longdouble.c
+++ b/numpy/core/src/common/npy_longdouble.c
@@ -172,8 +172,5 @@ npy_longdouble_from_PyLong(PyObject *long_obj) {
return -1;
}
- // Without this line, MSVC produces garbage (optimizes out result!?)
- printf("Double form is %f\n", (double) result);
-
return result;
}
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index d891f925a..afa44a627 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -30,6 +30,7 @@
#include <emmintrin.h>
#endif
+#include "npy_longdouble.h"
#include "numpyos.h"
#include <string.h>
@@ -331,9 +332,9 @@ string_to_long_double(PyObject*op)
/* Convert python long objects to a longdouble, without precision or range
* loss via a double.
*/
- if (PyLong_Check(op)
+ if ((PyLong_Check(op) && !PyBool_Check(op))
#if !defined(NPY_PY3K)
- || PyInt_Check(op)
+ || (PyInt_Check(op) && !PyBool_Check(op))
#endif
) {
return npy_longdouble_from_PyLong(op);
diff --git a/numpy/core/tests/test_longdouble.py b/numpy/core/tests/test_longdouble.py
index cf50d5d5c..66293e988 100644
--- a/numpy/core/tests/test_longdouble.py
+++ b/numpy/core/tests/test_longdouble.py
@@ -205,3 +205,17 @@ class TestCommaDecimalPointLocale(CommaDecimalPointLocale):
def test_fromstring_foreign_value(self):
b = np.fromstring("1,234", dtype=np.longdouble, sep=" ")
assert_array_equal(b[0], 1)
+
+@pytest.mark.parametrize("int_val", [
+ # cases discussed in gh-10723
+ # and gh-9968
+ 2 ** 1024, 0])
+def test_longdouble_from_int(int_val):
+ # for issue gh-9968
+ str_val = str(int_val)
+ assert np.longdouble(int_val) == np.longdouble(str_val)
+
+@pytest.mark.parametrize("bool_val", [
+ True, False])
+def test_longdouble_from_bool(bool_val):
+ assert np.longdouble(bool_val) == np.longdouble(int(bool_val))