Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src_c/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ vector_generic_math(PyObject *o1, PyObject *o2, int op)
Py_ssize_t i, dim;
double *vec_coords;
double other_coords[VECTOR_MAX_SIZE] = {0};
double tmp;
double tmp = 0.0;
PyObject *other;
pgVector *vec, *ret = NULL;
if (pgVector_Check(o1)) {
Expand All @@ -712,11 +712,15 @@ vector_generic_math(PyObject *o1, PyObject *o2, int op)
if (pg_VectorCoordsFromObj(other, dim, other_coords)) {
op |= OP_ARG_VECTOR;
}
else if (RealNumber_Check(other)) {
op |= OP_ARG_NUMBER;
}
else {
op |= OP_ARG_UNKNOWN;
tmp = PyFloat_AsDouble(other);
if (tmp == -1.0 && PyErr_Occurred()) {
PyErr_Clear();
op |= OP_ARG_UNKNOWN;
}
else {
op |= OP_ARG_NUMBER;
}
}

if (op & OP_INPLACE) {
Expand Down Expand Up @@ -761,14 +765,12 @@ vector_generic_math(PyObject *o1, PyObject *o2, int op)
case OP_MUL | OP_ARG_NUMBER:
case OP_MUL | OP_ARG_NUMBER | OP_ARG_REVERSE:
case OP_MUL | OP_ARG_NUMBER | OP_INPLACE:
tmp = PyFloat_AsDouble(other);
for (i = 0; i < dim; i++) {
ret->coords[i] = vec_coords[i] * tmp;
}
break;
case OP_DIV | OP_ARG_NUMBER:
case OP_DIV | OP_ARG_NUMBER | OP_INPLACE:
tmp = PyFloat_AsDouble(other);
if (tmp == 0.) {
PyErr_SetString(PyExc_ZeroDivisionError, "division by zero");
Py_DECREF(ret);
Expand All @@ -781,7 +783,6 @@ vector_generic_math(PyObject *o1, PyObject *o2, int op)
break;
case OP_FLOOR_DIV | OP_ARG_NUMBER:
case OP_FLOOR_DIV | OP_ARG_NUMBER | OP_INPLACE:
tmp = PyFloat_AsDouble(other);
if (tmp == 0.) {
PyErr_SetString(PyExc_ZeroDivisionError, "division by zero");
Py_DECREF(ret);
Expand Down Expand Up @@ -3971,12 +3972,15 @@ vector_elementwiseproxy_generic_math(PyObject *o1, PyObject *o2, int op)
return NULL;
}
}
else if (RealNumber_Check(other)) {
op |= OP_ARG_NUMBER;
other_value = PyFloat_AsDouble(other);
}
else {
op |= OP_ARG_UNKNOWN;
other_value = PyFloat_AsDouble(other);
if (other_value == -1.0 && PyErr_Occurred()) {
PyErr_Clear();
op |= OP_ARG_UNKNOWN;
}
else {
op |= OP_ARG_NUMBER;
}
}

ret = _vector_subtype_new(vec);
Expand Down
Loading