1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
#pragma once
#include "../../compiler_setup.h"
#include "../../internal_functions/all.h"
PyDoc_STRVAR(binary_add_docstr,
"add(a, b) -> Any\n"
" Equivalent to `a + b`."
);
static PyObject*
binary_add(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "add", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.add is deprecated. Use operator.add instead");
return PyNumber_Add(arg1, arg2);
}
PyDoc_STRVAR(binary_sub_docstr,
"sub(a, b) -> Any\n"
" Equivalent to `a - b`."
);
static PyObject*
binary_sub(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "sub", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.sub is deprecated. Use operator.sub instead");
return PyNumber_Subtract(arg1, arg2);
}
PyDoc_STRVAR(binary_mul_docstr,
"mul(a, b) -> Any\n"
" Equivalent to `a * b`."
);
static PyObject*
binary_mul(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "mul", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.mul is deprecated. Use operator.mul instead");
return PyNumber_Multiply(arg1, arg2);
}
PyDoc_STRVAR(binary_div_docstr,
"div(a, b) -> Any\n"
" Equivalent to `a / b`."
);
static PyObject*
binary_div(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "div", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.div is deprecated. Use operator.truediv instead");
return PyNumber_TrueDivide(arg1, arg2);
}
PyDoc_STRVAR(binary_floordiv_docstr,
"floordiv(a, b) -> Any\n"
" Equivalent to `a // b`."
);
static PyObject*
binary_floordiv(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "floordiv", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.floordiv is deprecated. Use operator.floordiv instead");
return PyNumber_FloorDivide(arg1, arg2);
}
PyDoc_STRVAR(binary_mod_docstr,
"mod(a, b) -> Any\n"
" Equivalent to `a % b`."
);
static PyObject*
binary_mod(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "mod", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.mod is deprecated. Use operator.mod instead");
return PyNumber_Remainder(arg1, arg2);
}
PyDoc_STRVAR(binary_lshift_docstr,
"lshift(a, b) -> Any\n"
" Equivalent to `a << b`."
);
static PyObject*
binary_lshift(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "lshift", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.lshift is deprecated. Use operator.lshift instead");
return PyNumber_Lshift(arg1, arg2);
}
PyDoc_STRVAR(binary_rshift_docstr,
"rshift(a, b) -> Any\n"
" Equivalent to `a >> b`."
);
static PyObject*
binary_rshift(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "rshift", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.rshift is deprecated. Use operator.rshift instead");
return PyNumber_Rshift(arg1, arg2);
}
PyDoc_STRVAR(binary_and_docstr,
"and_(a, b) -> Any\n"
" Equivalent to `a & b`."
);
static PyObject*
binary_and(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "band", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.band is deprecated. Use operator.and_ instead");
return PyNumber_And(arg1, arg2);
}
PyDoc_STRVAR(binary_xor_docstr,
"xor(a, b) -> Any\n"
" Equivalent to `a ^ b`."
);
static PyObject*
binary_xor(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "bxor", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.bxor is deprecated. Use operator.xor instead");
return PyNumber_Xor(arg1, arg2);
}
PyDoc_STRVAR(binary_or_docstr,
"or_(a, b) -> Any\n"
" Equivalent to `a | b`."
);
static PyObject*
binary_or(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "bor", arg1, arg2);
PyGLM_WARN_TYPE(PyGLM_OPERATOR_DEPRECATION_WARNING, PyExc_DeprecationWarning, "glm.bor is deprecated. Use operator.or_ instead");
return PyNumber_Or(arg1, arg2);
}
PyDoc_STRVAR(binary_cmp_docstr,
"cmp(a, b) -> Any\n"
" Equivalent to `-1 if a < b else 1 if a > b else 0`."
);
static PyObject*
binary_cmp(PyObject*, PyObject* args) {
PyObject* arg1, * arg2;
PyGLM_Arg_Unpack_2O(args, "cmp", arg1, arg2);
int cmpResult = PyObject_RichCompareBool(arg1, arg2, Py_EQ);
if (cmpResult == 1) {
return PyGLM_PyObject_FromNumber<int>(0);
}
if (cmpResult == -1) {
return NULL;
}
cmpResult = PyObject_RichCompareBool(arg1, arg2, Py_LT);
if (cmpResult == 1) {
return PyGLM_PyObject_FromNumber<int>(-1);
}
if (cmpResult == -1) {
return NULL;
}
return PyGLM_PyObject_FromNumber<int>(1);
}
#define BINARY_METHODS \
{ "add", (PyCFunction)binary_add, METH_VARARGS, binary_add_docstr }, \
{ "sub", (PyCFunction)binary_sub, METH_VARARGS, binary_sub_docstr }, \
{ "mul", (PyCFunction)binary_mul, METH_VARARGS, binary_mul_docstr }, \
{ "div", (PyCFunction)binary_div, METH_VARARGS, binary_div_docstr }, \
{ "floordiv", (PyCFunction)binary_floordiv, METH_VARARGS, binary_floordiv_docstr }, \
{ "mod", (PyCFunction)binary_mod, METH_VARARGS, binary_mod_docstr }, \
{ "lshift", (PyCFunction)binary_lshift, METH_VARARGS, binary_lshift_docstr }, \
{ "rshift", (PyCFunction)binary_rshift, METH_VARARGS, binary_rshift_docstr }, \
{ "and_", (PyCFunction)binary_and, METH_VARARGS, binary_and_docstr }, \
{ "xor", (PyCFunction)binary_xor, METH_VARARGS, binary_xor_docstr }, \
{ "or_", (PyCFunction)binary_or, METH_VARARGS, binary_or_docstr }, \
{ "cmp", (PyCFunction)binary_cmp, METH_VARARGS, binary_cmp_docstr }
|