return ratio;
}
+/* op is 0 for multiplication, 1 for division */
static PyObject *
-multiply_float_timedelta(PyObject *floatobj, PyDateTime_Delta *delta)
+multiply_truedivide_timedelta_float(PyDateTime_Delta *delta, PyObject *floatobj, int op)
{
PyObject *result = NULL;
PyObject *pyus_in = NULL, *temp, *pyus_out;
if (ratio == NULL) {
goto error;
}
- temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 0));
+ temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, op));
Py_DECREF(pyus_in);
pyus_in = NULL;
if (temp == NULL)
goto error;
- pyus_out = divide_nearest(temp, PyTuple_GET_ITEM(ratio, 1));
+ pyus_out = divide_nearest(temp, PyTuple_GET_ITEM(ratio, !op));
Py_DECREF(temp);
if (pyus_out == NULL)
goto error;
return result;
}
-static PyObject *
-truedivide_timedelta_float(PyDateTime_Delta *delta, PyObject *f)
-{
- PyObject *result = NULL;
- PyObject *pyus_in = NULL, *temp, *pyus_out;
- PyObject *ratio = NULL;
-
- pyus_in = delta_to_microseconds(delta);
- if (pyus_in == NULL)
- return NULL;
- ratio = get_float_as_integer_ratio(f);
- if (ratio == NULL) {
- goto error;
- }
- temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 1));
- Py_DECREF(pyus_in);
- pyus_in = NULL;
- if (temp == NULL)
- goto error;
- pyus_out = divide_nearest(temp, PyTuple_GET_ITEM(ratio, 0));
- Py_DECREF(temp);
- if (pyus_out == NULL)
- goto error;
- result = microseconds_to_delta(pyus_out);
- Py_DECREF(pyus_out);
- error:
- Py_XDECREF(pyus_in);
- Py_XDECREF(ratio);
-
- return result;
-}
-
static PyObject *
truedivide_timedelta_int(PyDateTime_Delta *delta, PyObject *i)
{
result = multiply_int_timedelta(right,
(PyDateTime_Delta *) left);
else if (PyFloat_Check(right))
- result = multiply_float_timedelta(right,
- (PyDateTime_Delta *) left);
+ result = multiply_truedivide_timedelta_float(
+ (PyDateTime_Delta *) left, right, 0);
}
else if (PyLong_Check(left))
result = multiply_int_timedelta(left,
(PyDateTime_Delta *) right);
else if (PyFloat_Check(left))
- result = multiply_float_timedelta(left,
- (PyDateTime_Delta *) right);
+ result = multiply_truedivide_timedelta_float(
+ (PyDateTime_Delta *) right, left, 0);
if (result == Py_NotImplemented)
Py_INCREF(result);
(PyDateTime_Delta *)left,
(PyDateTime_Delta *)right);
else if (PyFloat_Check(right))
- result = truedivide_timedelta_float(
- (PyDateTime_Delta *)left, right);
+ result = multiply_truedivide_timedelta_float(
+ (PyDateTime_Delta *)left, right, 1);
else if (PyLong_Check(right))
result = truedivide_timedelta_int(
(PyDateTime_Delta *)left, right);