don't implicitly convert doubles to ints

This commit is contained in:
Wenzel Jakob
2016-05-17 15:35:29 +02:00
parent a439ccaa0e
commit 3f200fab22
5 changed files with 22 additions and 0 deletions

View File

@@ -326,11 +326,15 @@ public:
} if (std::is_floating_point<T>::value) {
py_value = (py_type) PyFloat_AsDouble(src.ptr());
} else if (sizeof(T) <= sizeof(long)) {
if (PyFloat_Check(src.ptr()))
return false;
if (std::is_signed<T>::value)
py_value = (py_type) PyLong_AsLong(src.ptr());
else
py_value = (py_type) PyLong_AsUnsignedLong(src.ptr());
} else {
if (PyFloat_Check(src.ptr()))
return false;
if (std::is_signed<T>::value)
py_value = (py_type) PYBIND11_LONG_AS_LONGLONG(src.ptr());
else