implement true divide handler of the number protocol for Quantity

This commit is contained in:
wmayer
2018-10-27 15:27:27 +02:00
parent fb1b60a825
commit 1106404b1e
5 changed files with 11 additions and 10 deletions

View File

@@ -370,7 +370,6 @@ PyObject* QuantityPy::number_multiply_handler(PyObject *self, PyObject *other)
return 0;
}
#if PY_MAJOR_VERSION < 3
PyObject * QuantityPy::number_divide_handler (PyObject *self, PyObject *other)
{
if (!PyObject_TypeCheck(self, &(QuantityPy::Type))) {
@@ -389,17 +388,23 @@ PyObject * QuantityPy::number_divide_handler (PyObject *self, PyObject *other)
double b = PyFloat_AsDouble(other);
return new QuantityPy(new Quantity(*a / b) );
}
#if PY_MAJOR_VERSION < 3
else if (PyInt_Check(other)) {
Base::Quantity *a = static_cast<QuantityPy*>(self) ->getQuantityPtr();
double b = (double)PyInt_AsLong(other);
return new QuantityPy(new Quantity(*a / b) );
}
#endif
else if (PyLong_Check(other)) {
Base::Quantity *a = static_cast<QuantityPy*>(self) ->getQuantityPtr();
double b = (double)PyLong_AsLong(other);
return new QuantityPy(new Quantity(*a / b) );
}
else {
PyErr_SetString(PyExc_TypeError, "A Quantity can only be divided by Quantity or number");
return 0;
}
}
#endif
PyObject * QuantityPy::number_remainder_handler (PyObject *self, PyObject *other)
{