File: func_exponential.h

package info (click to toggle)
python-pyglm 2.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,008 kB
  • sloc: cpp: 53,029; python: 3,683; makefile: 7
file content (135 lines) | stat: -rw-r--r-- 5,465 bytes parent folder | download
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
#pragma once

#include "../../compiler_setup.h"

#include "../../types/all.h"

#include "../../internal_functions/all.h"

#include "../function_generator_macros.h"

PyDoc_STRVAR(pow_docstr,
	"pow(base: float, exponent: float) -> float\n"
	"	Returns base raised to the power exponent.\n"
	"pow(base: vecN, exponent: vecN) -> vecN\n"
	"	For every index `i`:\n"
	"	Returns `base[i]` raised to the power `exponent[i]`.\n"
	"pow(base: quat, exponent: quat) -> quat\n"
	"	Returns a quaternion raised to a power."
);
static PyObject*
pow_(PyObject*, PyObject* args) {
	PyObject *arg1, *arg2;
	PyGLM_Arg_Unpack_2O(args, "pow", arg1, arg2);
	if (PyGLM_Number_Check(arg1) && PyGLM_Number_Check(arg2)) {
		return pack(glm::pow(PyGLM_Number_FromPyObject<double>(arg1), PyGLM_Number_FromPyObject<double>(arg2)));
	}
	PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_T_QUA | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
	PyGLM_PTI_Init1(arg2, PyGLM_T_VEC | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
	if (PyGLM_Vec_PTI_Check0(1, float, arg1) && PyGLM_Vec_PTI_Check1(1, float, arg2)) {
		return pack(glm::pow(PyGLM_Vec_PTI_Get0(1, float, arg1), PyGLM_Vec_PTI_Get1(1, float, arg2)));
	}
	if (PyGLM_Vec_PTI_Check0(1, double, arg1) && PyGLM_Vec_PTI_Check1(1, double, arg2)) {
		return pack(glm::pow(PyGLM_Vec_PTI_Get0(1, double, arg1), PyGLM_Vec_PTI_Get1(1, double, arg2)));
	}
	if (PyGLM_Vec_PTI_Check0(2, float, arg1) && PyGLM_Vec_PTI_Check1(2, float, arg2)) {
		return pack(glm::pow(PyGLM_Vec_PTI_Get0(2, float, arg1), PyGLM_Vec_PTI_Get1(2, float, arg2)));
	}
	if (PyGLM_Vec_PTI_Check0(2, double, arg1) && PyGLM_Vec_PTI_Check1(2, double, arg2)) {
		return pack(glm::pow(PyGLM_Vec_PTI_Get0(2, double, arg1), PyGLM_Vec_PTI_Get1(2, double, arg2)));
	}
	if (PyGLM_Vec_PTI_Check0(3, float, arg1) && PyGLM_Vec_PTI_Check1(3, float, arg2)) {
		return pack(glm::pow(PyGLM_Vec_PTI_Get0(3, float, arg1), PyGLM_Vec_PTI_Get1(3, float, arg2)));
	}
	if (PyGLM_Vec_PTI_Check0(3, double, arg1) && PyGLM_Vec_PTI_Check1(3, double, arg2)) {
		return pack(glm::pow(PyGLM_Vec_PTI_Get0(3, double, arg1), PyGLM_Vec_PTI_Get1(3, double, arg2)));
	}
	if (PyGLM_Vec_PTI_Check0(4, float, arg1) && PyGLM_Vec_PTI_Check1(4, float, arg2)) {
		return pack(glm::pow(PyGLM_Vec_PTI_Get0(4, float, arg1), PyGLM_Vec_PTI_Get1(4, float, arg2)));
	}
	if (PyGLM_Vec_PTI_Check0(4, double, arg1) && PyGLM_Vec_PTI_Check1(4, double, arg2)) {
		return pack(glm::pow(PyGLM_Vec_PTI_Get0(4, double, arg1), PyGLM_Vec_PTI_Get1(4, double, arg2)));
	}

	if (PyGLM_Qua_PTI_Check0(float, arg1) && PyGLM_Number_Check(arg2)) {
		return pack(glm::pow(PyGLM_Qua_PTI_Get0(float, arg1), PyGLM_Number_FromPyObject<float>(arg2)));
	}
	if (PyGLM_Qua_PTI_Check0(double, arg1) && PyGLM_Number_Check(arg2)) {
		return pack(glm::pow(PyGLM_Qua_PTI_Get0(double, arg1), PyGLM_Number_FromPyObject<double>(arg2)));
	}
	PyGLM_TYPEERROR_2O("invalid argument type(s) for pow(): ", arg1, arg2);
	return NULL;
}

PyDoc_STRVAR(exp_docstr,
	"exp(x: float) -> float\n"
	"	Returns the natural exponentiation of `x`, i.e., `e^x`.\n"
	"exp(x: vecN) -> vecN\n"
	"	For every component c of x:\n"
	"	Returns the natural exponentiation of `c`, i.e., `e^c`.\n"
	"exp(x: quat) -> quat\n"
	"	Returns an exponential of a quaternion."
);
PyGLM_MAKE_GLM_FUNC_N_V_Q__tfF(exp)

PyDoc_STRVAR(log_docstr,
	"log(x: float) -> float\n"
	"	Returns the natural logarithm of `x`, i.e., returns the value `y` which satisfies the equation\n"
	"	`x = e^y`. Results are undefined if `x <= 0`.\n"
	"log(x: vecN) -> vecN\n"
	"	For every component `c` of `x`:\n"
	"	Returns the natural logarithm of `c`, i.e., returns the value `y` which satisfies the equation\n"
	"	`c = e^y`. Results are undefined if `c <= 0`.\n"
	"log(x: quat) -> quat\n"
	"	Returns a logarithm of a quaternion."
);
PyGLM_MAKE_GLM_FUNC_N_V_Q__tfF(log)

PyDoc_STRVAR(exp2_docstr,
	"exp2(x: float) -> float\n"
	"	Returns `2` raised to the `x` power.\n"
	"exp2(x: vecN) -> vecN\n"
	"	For every component `c` of `x`:\n"
	"	Returns `2` raised to the `c` power."
);
PyGLM_MAKE_GLM_FUNC_N_V__tfF(exp2)

PyDoc_STRVAR(log2_docstr,
	"log2(x: float) -> float\n"
	"	Returns the base `2` log of `x`, i.e., returns the value `y`, which satisfies the equation\n"
	"	`x = 2 ^ y`.\n"
	"log2(x: vecN) -> vecN\n"
	"	For every component `c` of `x`:\n"
	"	Returns the base `2` log of `c`, i.e., returns the value `y`, which satisfies the equation\n"
	"	`c = 2 ^ y`."
);
PyGLM_MAKE_GLM_FUNC_N_V__tfF(log2)

PyDoc_STRVAR(sqrt_docstr,
	"sqrt(x: float) -> float\n"
	"	Returns the positive square root of `x`.\n"
	"sqrt(x: vecN) -> vecN\n"
	"	For every component `c` of `x`:\n"
	"	Returns the positive square root of `c`.\n"
	"sqrt(x: quat) -> quat\n"
	"	Returns the square root of a quaternion."
);
PyGLM_MAKE_GLM_FUNC_N_V_Q__tfF(sqrt)

PyDoc_STRVAR(inversesqrt_docstr,
	"inversesqrt(x: float) -> float\n"
	"	Returns the reciprocal of the positive square root of `x`.\n"
	"inversesqrt(x: vecN) -> vecN\n"
	"	For every component `c` of `x`:\n"
	"	Returns the reciprocal of the positive square root of `c`."
);
PyGLM_MAKE_GLM_FUNC_N_V__tfF(inversesqrt)

#define FUNC_EXPONENTIAL \
{ "pow", (PyCFunction)pow_, METH_VARARGS, pow_docstr }, \
{ "exp", (PyCFunction)exp_, METH_O, exp_docstr }, \
{ "log", (PyCFunction)log_, METH_O, log_docstr }, \
{ "exp2", (PyCFunction)exp2_, METH_O, exp2_docstr }, \
{ "log2", (PyCFunction)log2_, METH_O, log2_docstr }, \
{ "sqrt", (PyCFunction)sqrt_, METH_O, sqrt_docstr }, \
{ "inversesqrt", (PyCFunction)inversesqrt_, METH_O, inversesqrt_docstr }