Skip to content

Instantly share code, notes, and snippets.

@arpitbbhayani
Created January 2, 2020 19:31
Show Gist options
  • Save arpitbbhayani/ca62e68a31cb3d2b83637373ad00d4a9 to your computer and use it in GitHub Desktop.
Save arpitbbhayani/ca62e68a31cb3d2b83637373ad00d4a9 to your computer and use it in GitHub Desktop.
Binary operate
PyObject *
binary_operate(PyObject * left, PyObject * right, char operator) {
switch (operator) {
case '+':
return PyNumber_Add(left, right);
case '-':
return PyNumber_Subtract(left, right);
case '*':
return PyNumber_Multiply(left, right);
case '/':
return PyNumber_FloorDivide(left, right);
case '^':
return PyNumber_Power(left, right, Py_None);
default:
return NULL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment