Xonotic
mathlib.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define M_PI   3.14159265358979323846 /* pi */
 

Functions

float acosh (float e)
 
float asinh (float e)
 
float atanh (float e)
 
float cbrt (float e)
 
float copysign (float e, float f)
 
float cosh (float e)
 
float erf (float e)
 
float erfc (float e)
 
float exp (float e)
 
float exp2 (float e)
 
float expm1 (float e)
 
float fdim (float e, float f)
 
float fma (float e, float f, float g)
 
float fmax (float e, float f)
 
float fmin (float e, float f)
 
float fmod (float e, float f)
 
int fpclassify (float e)
 
vector frexp (float e)
 
float hypot (float e, float f)
 
int ilogb (float e)
 
bool isfinite (float e)
 
int isgreater (float e, float f)
 
int isgreaterequal (float e, float f)
 
bool isinf (float e)
 
int isless (float e, float f)
 
int islessequal (float e, float f)
 
int islessgreater (float e, float f)
 
bool isnan (float e)
 
bool isnormal (float e)
 
int isunordered (float e, float f)
 
float ldexp (float e, int e)
 
vector lgamma (float e)
 
float log10 (float e)
 
float log1p (float e)
 
float log2 (float e)
 
float logb (float e)
 
float logn (float e, float base)
 
vector modf (float f)
 
float nan (string tag)
 
float nearbyint (float e)
 
float nextafter (float e, float f)
 
float nexttoward (float e, float f)
 
float pymod (float e, float f)
 Pythonic mod: TODO: %% operator? More...
 
float remainder (float e, float f)
 
vector remquo (float e, float f)
 
float scalbn (float e, int n)
 
bool signbit (float e)
 
float sinh (float e)
 
float tanh (float e)
 
float tgamma (float e)
 
float trunc (float e)
 

Variables

const int FP_INFINITE = 1
 
const int FP_NAN = 0
 
const int FP_NORMAL = 4
 
const int FP_SUBNORMAL = 3
 
const int FP_ZERO = 2
 
const float M_1_PI = 0.31830988618379067154
 
const float M_2_PI = 0.63661977236758134308
 
const float M_2_SQRTPI = 1.12837916709551257390
 
const float M_E = 2.7182818284590452354
 
const float M_LN10 = 2.30258509299404568402
 
const float M_LN2 = 0.69314718055994530942
 
const float M_LOG10E = 0.43429448190325182765
 
const float M_LOG2E = 1.4426950408889634074
 
const float M_PI_2 = 1.57079632679489661923
 
const float M_PI_4 = 0.78539816339744830962
 
const float M_SQRT1_2 = 0.70710678118654752440
 
const float M_SQRT2 = 1.41421356237309504880
 

Macro Definition Documentation

◆ M_PI

#define M_PI   3.14159265358979323846 /* pi */

Definition at line 108 of file mathlib.qh.

Function Documentation

◆ acosh()

float acosh ( float  e)

Definition at line 48 of file mathlib.qc.

References log(), and sqrt().

49 {
50  return log(e + sqrt(e*e - 1));
51 }
float log(float f)
+ Here is the call graph for this function:

◆ asinh()

float asinh ( float  e)

Definition at line 52 of file mathlib.qc.

References log(), and sqrt().

53 {
54  return log(e + sqrt(e*e + 1));
55 }
float log(float f)
+ Here is the call graph for this function:

◆ atanh()

float atanh ( float  e)

Definition at line 56 of file mathlib.qc.

References log().

57 {
58  return 0.5 * log((1+e) / (1-e));
59 }
float log(float f)
+ Here is the call graph for this function:

◆ cbrt()

float cbrt ( float  e)

Definition at line 132 of file mathlib.qc.

References copysign(), fabs(), and pow().

Referenced by solve_cubic_pq().

133 {
134  return copysign(pow(fabs(e), (1.0/3.0)), e);
135 }
float copysign(float e, float f)
Definition: mathlib.qc:225
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copysign()

float copysign ( float  e,
float  f 
)

Definition at line 225 of file mathlib.qc.

References fabs().

Referenced by AdjustAirAccelQW(), cbrt(), erf(), and lgamma().

226 {
227  return fabs(e) * ((f>0) ? 1 : -1);
228 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cosh()

float cosh ( float  e)

Definition at line 60 of file mathlib.qc.

References exp().

Referenced by tanh().

61 {
62  return 0.5 * (exp(e) + exp(-e));
63 }
float exp(float e)
Definition: mathlib.qc:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ erf()

float erf ( float  e)

Definition at line 141 of file mathlib.qc.

References copysign(), exp(), and sqrt().

Referenced by erfc().

142 {
143  // approximation taken from wikipedia
144  float f;
145  f = e*e;
146  return copysign(sqrt(1 - exp(-f * (1.273239544735163 + 0.14001228868667 * f) / (1 + 0.14001228868667 * f))), e);
147 }
float copysign(float e, float f)
Definition: mathlib.qc:225
float exp(float e)
Definition: mathlib.qc:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ erfc()

float erfc ( float  e)

Definition at line 148 of file mathlib.qc.

References erf().

149 {
150  return 1.0 - erf(e);
151 }
float erf(float e)
Definition: mathlib.qc:141
+ Here is the call graph for this function:

◆ exp()

float exp ( float  e)

Definition at line 73 of file mathlib.qc.

References M_E, and pow().

Referenced by anticheat_physics(), cosh(), erf(), expm1(), fromDecibelOfSquare(), GenericCommand_rpn(), GetCurrentFov(), ListBox_draw(), sinh(), tgamma(), and toDecibelOfSquare().

74 {
75  return pow(M_E, e);
76 }
const float M_E
Definition: mathlib.qh:102
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exp2()

float exp2 ( float  e)

Definition at line 77 of file mathlib.qc.

References pow().

78 {
79  return pow(2, e);
80 }
+ Here is the call graph for this function:

◆ expm1()

float expm1 ( float  e)

Definition at line 81 of file mathlib.qc.

References exp().

82 {
83  return exp(e) - 1;
84 }
float exp(float e)
Definition: mathlib.qc:73
+ Here is the call graph for this function:

◆ fdim()

float fdim ( float  e,
float  f 
)

Definition at line 260 of file mathlib.qc.

References max().

261 {
262  return max(e-f, 0);
263 }
+ Here is the call graph for this function:

◆ fma()

float fma ( float  e,
float  f,
float  g 
)

Definition at line 272 of file mathlib.qc.

273 {
274  return e * f + g;
275 }

◆ fmax()

float fmax ( float  e,
float  f 
)

Definition at line 264 of file mathlib.qc.

References max().

265 {
266  return max(e, f);
267 }
+ Here is the call graph for this function:

◆ fmin()

float fmin ( float  e,
float  f 
)

Definition at line 268 of file mathlib.qc.

References min().

269 {
270  return min(e, f);
271 }
+ Here is the call graph for this function:

◆ fmod()

float fmod ( float  e,
float  f 
)

Definition at line 208 of file mathlib.qc.

References trunc().

Referenced by CSQCModel_Effects_Apply().

209 {
210  return e - f * trunc(e / f);
211 }
float trunc(float e)
Definition: mathlib.qc:203
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fpclassify()

int fpclassify ( float  e)

Definition at line 7 of file mathlib.qc.

References FP_INFINITE, FP_NAN, FP_NORMAL, FP_ZERO, isinf(), and isnan().

8 {
9  if(isnan(e))
10  return FP_NAN;
11  if(isinf(e))
12  return FP_INFINITE;
13  if(e == 0)
14  return FP_ZERO;
15  return FP_NORMAL;
16 }
const int FP_NORMAL
Definition: mathlib.qh:12
const int FP_NAN
Definition: mathlib.qh:8
const int FP_INFINITE
Definition: mathlib.qh:9
const int FP_ZERO
Definition: mathlib.qh:10
bool isinf(float e)
Definition: mathlib.qc:21
bool isnan(float e)
Definition: mathlib.qc:25
+ Here is the call graph for this function:

◆ frexp()

vector frexp ( float  e)

Definition at line 86 of file mathlib.qc.

References ilogb(), pow(), v, and vector().

87 {
88  vector v;
89  v.z = 0;
90  v.y = ilogb(e) + 1;
91  v.x = e / pow(2, v.y);
92  return v;
93 }
int ilogb(float e)
Definition: mathlib.qc:94
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
+ Here is the call graph for this function:

◆ hypot()

float hypot ( float  e,
float  f 
)

Definition at line 136 of file mathlib.qc.

References sqrt().

137 {
138  return sqrt(e*e + f*f);
139 }
+ Here is the call graph for this function:

◆ ilogb()

int ilogb ( float  e)

Definition at line 94 of file mathlib.qc.

References fabs(), floor(), and log2().

Referenced by frexp().

95 {
96  return floor(log2(fabs(e)));
97 }
float log2(float e)
Definition: mathlib.qc:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isfinite()

bool isfinite ( float  e)

Definition at line 17 of file mathlib.qc.

References isinf(), and isnan().

Referenced by isnormal(), and lgamma().

18 {
19  return !(isnan(e) || isinf(e));
20 }
bool isinf(float e)
Definition: mathlib.qc:21
bool isnan(float e)
Definition: mathlib.qc:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isgreater()

int isgreater ( float  e,
float  f 
)

Definition at line 277 of file mathlib.qc.

278 {
279  return e > f;
280 }

◆ isgreaterequal()

int isgreaterequal ( float  e,
float  f 
)

Definition at line 281 of file mathlib.qc.

282 {
283  return e >= f;
284 }

◆ isinf()

bool isinf ( float  e)

Definition at line 21 of file mathlib.qc.

Referenced by fpclassify(), and isfinite().

22 {
23  return (e != 0) && (e + e == e);
24 }
+ Here is the caller graph for this function:

◆ isless()

int isless ( float  e,
float  f 
)

Definition at line 285 of file mathlib.qc.

286 {
287  return e < f;
288 }

◆ islessequal()

int islessequal ( float  e,
float  f 
)

Definition at line 289 of file mathlib.qc.

290 {
291  return e <= f;
292 }

◆ islessgreater()

int islessgreater ( float  e,
float  f 
)

Definition at line 293 of file mathlib.qc.

294 {
295  return e < f || e > f;
296 }

◆ isnan()

bool isnan ( float  e)

Definition at line 25 of file mathlib.qc.

References ftos().

Referenced by fpclassify(), is_all_nans(), and isfinite().

26 {
27  // The sane way to detect NaN is this:
28  // float f = e;
29  // return (e != f);
30  // but darkplaces used to be compiled with -ffinite-math-only which broke it.
31  // DP is fixed now but until all clients update (so after 0.8.3) we have to use the following workaround
32  // or they'd have issues when connecting to newer servers.
33 
34  // Negative NaN ("-nan") is much more common but plain "nan" can be created by negating *some* -nans so we need to check both.
35  // DP's QCVM and GMQCC's QCVM behave differently - one needs ftos(-(0.0 / 0.0)), the other ftos(-sqrt(-1)).
36  string s = ftos(e);
37  return s == "nan" || s == "-nan";
38 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isnormal()

bool isnormal ( float  e)

Definition at line 39 of file mathlib.qc.

References isfinite().

40 {
41  return isfinite(e);
42 }
bool isfinite(float e)
Definition: mathlib.qc:17
+ Here is the call graph for this function:

◆ isunordered()

int isunordered ( float  e,
float  f 
)

Definition at line 297 of file mathlib.qc.

298 {
299  return !(e < f || e == f || e > f);
300 }

◆ ldexp()

float ldexp ( float  e,
int  e 
)

Definition at line 98 of file mathlib.qc.

References pow().

99 {
100  return x * pow(2, e);
101 }
+ Here is the call graph for this function:

◆ lgamma()

vector lgamma ( float  e)

Definition at line 152 of file mathlib.qc.

References copysign(), fabs(), floor(), isfinite(), lgamma(), log(), M_PI, nan(), sin(), v, and vector().

Referenced by lgamma(), and tgamma().

153 {
154  // TODO improve accuracy
155  if(!isfinite(e))
156  return fabs(e) * '1 0 0' + copysign(1, e) * '0 1 0';
157  if(e < 1 && e == floor(e))
158  return nan("gamma") * '1 1 1';
159  if(e < 0.1)
160  {
161  vector v;
162  v = lgamma(1.0 - e);
163  // reflection formula:
164  // gamma(1-z) * gamma(z) = pi / sin(pi*z)
165  // lgamma(1-z) + lgamma(z) = log(pi) - log(sin(pi*z))
166  // sign of gamma(1-z) = sign of gamma(z) * sign of sin(pi*z)
167  v.z = sin(M_PI * e);
168  v.x = log(M_PI) - log(fabs(v.z)) - v.x;
169  if(v.z < 0)
170  v.y = -v.y;
171  v.z = 0;
172  return v;
173  }
174  if(e < 1.1)
175  return lgamma(e + 1) - log(e) * '1 0 0';
176  e -= 1;
177  return (0.5 * log(2 * M_PI * e) + e * (log(e) - 1)) * '1 0 0' + '0 1 0';
178 }
bool isfinite(float e)
Definition: mathlib.qc:17
float copysign(float e, float f)
Definition: mathlib.qc:225
vector lgamma(float e)
Definition: mathlib.qc:152
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const float M_PI
Definition: csprogsdefs.qc:269
float nan(string tag)
Definition: mathlib.qc:230
vector v
Definition: ent_cs.qc:116
float log(float f)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ log10()

float log10 ( float  e)

Definition at line 106 of file mathlib.qc.

References log(), and M_LOG10E.

107 {
108  return log(e) * M_LOG10E;
109 }
float log(float f)
const float M_LOG10E
Definition: mathlib.qh:104
+ Here is the call graph for this function:

◆ log1p()

float log1p ( float  e)

Definition at line 110 of file mathlib.qc.

References log().

111 {
112  return log(e + 1);
113 }
float log(float f)
+ Here is the call graph for this function:

◆ log2()

float log2 ( float  e)

Definition at line 114 of file mathlib.qc.

References log(), and M_LOG2E.

Referenced by ilogb(), and logb().

115 {
116  return log(e) * M_LOG2E;
117 }
float log(float f)
const float M_LOG2E
Definition: mathlib.qh:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logb()

float logb ( float  e)

Definition at line 118 of file mathlib.qc.

References fabs(), floor(), and log2().

119 {
120  return floor(log2(fabs(e)));
121 }
float log2(float e)
Definition: mathlib.qc:114
+ Here is the call graph for this function:

◆ logn()

float logn ( float  e,
float  base 
)

Definition at line 102 of file mathlib.qc.

References log().

Referenced by buff_Inferno_CalculateTime().

103 {
104  return log(e) / log(base);
105 }
float log(float f)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ modf()

vector modf ( float  f)

Definition at line 122 of file mathlib.qc.

References trunc().

123 {
124  return '1 0 0' * (f - trunc(f)) + '0 1 0' * trunc(f);
125 }
float trunc(float e)
Definition: mathlib.qc:203
+ Here is the call graph for this function:

◆ nan()

float nan ( string  tag)

Definition at line 230 of file mathlib.qc.

References sqrt().

Referenced by lgamma(), and nextafter().

231 {
232  return sqrt(-1);
233 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nearbyint()

float nearbyint ( float  e)

Definition at line 199 of file mathlib.qc.

References rint().

200 {
201  return rint(e);
202 }
+ Here is the call graph for this function:

◆ nextafter()

float nextafter ( float  e,
float  f 
)

Definition at line 234 of file mathlib.qc.

References fabs(), max(), nan(), and nextafter().

Referenced by nextafter(), and nexttoward().

235 {
236  // TODO very crude
237  if(e == f)
238  return nan("nextafter");
239  if(e > f)
240  return -nextafter(-e, -f);
241  // now we know that e < f
242  // so we need the next number > e
243  float d, a, b;
244  d = max(fabs(e), 0.00000000000000000000001);
245  a = e + d;
246  do
247  {
248  d *= 0.5;
249  b = a;
250  a = e + d;
251  }
252  while(a != e);
253  return b;
254 }
float nan(string tag)
Definition: mathlib.qc:230
float nextafter(float e, float f)
Definition: mathlib.qc:234
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nexttoward()

float nexttoward ( float  e,
float  f 
)

Definition at line 255 of file mathlib.qc.

References nextafter().

256 {
257  return nextafter(e, f);
258 }
float nextafter(float e, float f)
Definition: mathlib.qc:234
+ Here is the call graph for this function:

◆ pymod()

float pymod ( float  e,
float  f 
)

Pythonic mod: TODO: %% operator?

1 % 2 == 1 -1 % 2 == 1 1 % -2 == -1 -1 % -2 == -1

Definition at line 194 of file mathlib.qc.

References floor().

195 {
196  return e - f * floor(e / f);
197 }
+ Here is the call graph for this function:

◆ remainder()

float remainder ( float  e,
float  f 
)

Definition at line 212 of file mathlib.qc.

References rint().

Referenced by IsMoveInDirection().

213 {
214  return e - f * rint(e / f);
215 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remquo()

vector remquo ( float  e,
float  f 
)

Definition at line 216 of file mathlib.qc.

References rint(), v, and vector().

217 {
218  vector v;
219  v.z = 0;
220  v.y = rint(e / f);
221  v.x = e - f * v.y;
222  return v;
223 }
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
+ Here is the call graph for this function:

◆ scalbn()

float scalbn ( float  e,
int  n 
)

Definition at line 127 of file mathlib.qc.

References pow().

128 {
129  return e * pow(2, n);
130 }
+ Here is the call graph for this function:

◆ signbit()

bool signbit ( float  e)

Definition at line 43 of file mathlib.qc.

44 {
45  return (e < 0);
46 }

◆ sinh()

float sinh ( float  e)

Definition at line 64 of file mathlib.qc.

References exp().

Referenced by tanh().

65 {
66  return 0.5 * (exp(e) - exp(-e));
67 }
float exp(float e)
Definition: mathlib.qc:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tanh()

float tanh ( float  e)

Definition at line 68 of file mathlib.qc.

References cosh(), and sinh().

Referenced by ctf_CalculatePassVelocity().

69 {
70  return sinh(e) / cosh(e);
71 }
float cosh(float e)
Definition: mathlib.qc:60
float sinh(float e)
Definition: mathlib.qc:64
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tgamma()

float tgamma ( float  e)

Definition at line 179 of file mathlib.qc.

References exp(), lgamma(), v, and vector().

180 {
181  vector v = lgamma(e);
182  return exp(v.x) * v.y;
183 }
vector lgamma(float e)
Definition: mathlib.qc:152
float exp(float e)
Definition: mathlib.qc:73
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
+ Here is the call graph for this function:

◆ trunc()

float trunc ( float  e)

Definition at line 203 of file mathlib.qc.

References ceil(), and floor().

Referenced by fmod(), and modf().

204 {
205  return (e>=0) ? floor(e) : ceil(e);
206 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ FP_INFINITE

const int FP_INFINITE = 1

Definition at line 9 of file mathlib.qh.

Referenced by fpclassify().

◆ FP_NAN

const int FP_NAN = 0

Definition at line 8 of file mathlib.qh.

Referenced by fpclassify().

◆ FP_NORMAL

const int FP_NORMAL = 4

Definition at line 12 of file mathlib.qh.

Referenced by fpclassify().

◆ FP_SUBNORMAL

const int FP_SUBNORMAL = 3

Definition at line 11 of file mathlib.qh.

◆ FP_ZERO

const int FP_ZERO = 2

Definition at line 10 of file mathlib.qh.

Referenced by fpclassify().

◆ M_1_PI

const float M_1_PI = 0.31830988618379067154

Definition at line 111 of file mathlib.qh.

◆ M_2_PI

const float M_2_PI = 0.63661977236758134308

Definition at line 112 of file mathlib.qh.

◆ M_2_SQRTPI

const float M_2_SQRTPI = 1.12837916709551257390

Definition at line 113 of file mathlib.qh.

◆ M_E

const float M_E = 2.7182818284590452354

Definition at line 102 of file mathlib.qh.

Referenced by colormapPaletteColor_(), and exp().

◆ M_LN10

const float M_LN10 = 2.30258509299404568402

Definition at line 106 of file mathlib.qh.

◆ M_LN2

const float M_LN2 = 0.69314718055994530942

Definition at line 105 of file mathlib.qh.

◆ M_LOG10E

const float M_LOG10E = 0.43429448190325182765

Definition at line 104 of file mathlib.qh.

Referenced by log10().

◆ M_LOG2E

const float M_LOG2E = 1.4426950408889634074

Definition at line 103 of file mathlib.qh.

Referenced by log2().

◆ M_PI_2

const float M_PI_2 = 1.57079632679489661923

Definition at line 109 of file mathlib.qh.

◆ M_PI_4

const float M_PI_4 = 0.78539816339744830962

Definition at line 110 of file mathlib.qh.

◆ M_SQRT1_2

const float M_SQRT1_2 = 0.70710678118654752440

Definition at line 115 of file mathlib.qh.

Referenced by MUTATOR_HOOKFUNCTION().

◆ M_SQRT2

const float M_SQRT2 = 1.41421356237309504880

Definition at line 114 of file mathlib.qh.

Referenced by havocbot_movetogoal().