Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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?
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

Function Documentation

◆ acosh()

float acosh ( float e)

Definition at line 48 of file mathlib.qc.

49{
50 return log(e + sqrt(e*e - 1));
51}
float log(float f)
float sqrt(float f)

References log(), and sqrt().

◆ asinh()

float asinh ( float e)

Definition at line 52 of file mathlib.qc.

53{
54 return log(e + sqrt(e*e + 1));
55}

References log(), and sqrt().

◆ atanh()

float atanh ( float e)

Definition at line 56 of file mathlib.qc.

57{
58 return 0.5 * log((1+e) / (1-e));
59}

References log().

◆ cbrt()

float cbrt ( float e)

Definition at line 132 of file mathlib.qc.

133{
134 return copysign(pow(fabs(e), (1.0/3.0)), e);
135}
#define pow(a, b)
Definition _all.inc:67
float copysign(float e, float f)
Definition mathlib.qc:225
float fabs(float f)

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

Referenced by solve_cubic_pq().

◆ copysign()

float copysign ( float e,
float f )

Definition at line 225 of file mathlib.qc.

226{
227 return fabs(e) * ((f>0) ? 1 : -1);
228}

References fabs().

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

◆ cosh()

float cosh ( float e)

Definition at line 60 of file mathlib.qc.

61{
62 return 0.5 * (exp(e) + exp(-e));
63}
float exp(float e)
Definition mathlib.qc:73

References exp().

Referenced by tanh().

◆ erf()

float erf ( float e)

Definition at line 141 of file mathlib.qc.

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}

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

Referenced by erfc().

◆ erfc()

float erfc ( float e)

Definition at line 148 of file mathlib.qc.

149{
150 return 1.0 - erf(e);
151}
float erf(float e)
Definition mathlib.qc:141

References erf().

◆ exp()

◆ exp2()

float exp2 ( float e)

Definition at line 77 of file mathlib.qc.

78{
79 return pow(2, e);
80}

References pow.

◆ expm1()

float expm1 ( float e)

Definition at line 81 of file mathlib.qc.

82{
83 return exp(e) - 1;
84}

References exp().

◆ fdim()

float fdim ( float e,
float f )

Definition at line 260 of file mathlib.qc.

261{
262 return max(e-f, 0);
263}
float max(float f,...)

References max().

◆ 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.

265{
266 return max(e, f);
267}

References max().

◆ fmin()

float fmin ( float e,
float f )

Definition at line 268 of file mathlib.qc.

269{
270 return min(e, f);
271}
float min(float f,...)

References min().

◆ fmod()

float fmod ( float e,
float f )

Definition at line 208 of file mathlib.qc.

209{
210 return e - f * trunc(e / f);
211}
float trunc(float e)
Definition mathlib.qc:203

References trunc().

Referenced by CSQCModel_Effects_Apply().

◆ fpclassify()

int fpclassify ( float e)

Definition at line 7 of file mathlib.qc.

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}
bool isinf(float e)
Definition mathlib.qc:21
bool isnan(float e)
Definition mathlib.qc:25
const int FP_NAN
Definition mathlib.qh:8
const int FP_NORMAL
Definition mathlib.qh:12
const int FP_INFINITE
Definition mathlib.qh:9
const int FP_ZERO
Definition mathlib.qh:10

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

◆ frexp()

vector frexp ( float e)

Definition at line 86 of file mathlib.qc.

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
Definition self.qh:92

References ilogb(), pow, and vector.

◆ hypot()

float hypot ( float e,
float f )

Definition at line 136 of file mathlib.qc.

137{
138 return sqrt(e*e + f*f);
139}

References sqrt().

◆ ilogb()

int ilogb ( float e)

Definition at line 94 of file mathlib.qc.

95{
96 return floor(log2(fabs(e)));
97}
float log2(float e)
Definition mathlib.qc:114
float floor(float f)

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

Referenced by frexp().

◆ isfinite()

bool isfinite ( float e)

Definition at line 17 of file mathlib.qc.

18{
19 return !(isnan(e) || isinf(e));
20}

References isinf(), and isnan().

Referenced by isnormal(), and lgamma().

◆ 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.

22{
23 return (e != 0) && (e + e == e);
24}

Referenced by fpclassify(), and isfinite().

◆ 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.

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}
string ftos(float f)

References ftos().

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

◆ isnormal()

bool isnormal ( float e)

Definition at line 39 of file mathlib.qc.

40{
41 return isfinite(e);
42}
bool isfinite(float e)
Definition mathlib.qc:17

References isfinite().

◆ 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.

99{
100 return x * pow(2, e);
101}

References pow.

◆ lgamma()

vector lgamma ( float e)

Definition at line 152 of file mathlib.qc.

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}
float nan(string tag)
Definition mathlib.qc:230
vector lgamma(float e)
Definition mathlib.qc:152
#define M_PI
Definition mathlib.qh:108
float sin(float f)

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

Referenced by lgamma(), and tgamma().

◆ log10()

float log10 ( float e)

Definition at line 106 of file mathlib.qc.

107{
108 return log(e) * M_LOG10E;
109}
const float M_LOG10E
Definition mathlib.qh:104

References log(), and M_LOG10E.

◆ log1p()

float log1p ( float e)

Definition at line 110 of file mathlib.qc.

111{
112 return log(e + 1);
113}

References log().

◆ log2()

float log2 ( float e)

Definition at line 114 of file mathlib.qc.

115{
116 return log(e) * M_LOG2E;
117}
const float M_LOG2E
Definition mathlib.qh:103

References log(), and M_LOG2E.

Referenced by ilogb(), and logb().

◆ logb()

float logb ( float e)

Definition at line 118 of file mathlib.qc.

119{
120 return floor(log2(fabs(e)));
121}

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

◆ logn()

float logn ( float e,
float base )

Definition at line 102 of file mathlib.qc.

103{
104 return log(e) / log(base);
105}

References log().

Referenced by buff_Inferno_CalculateTime().

◆ modf()

vector modf ( float f)

Definition at line 122 of file mathlib.qc.

123{
124 return '1 0 0' * (f - trunc(f)) + '0 1 0' * trunc(f);
125}

References trunc(), and vector.

◆ nan()

float nan ( string tag)

Definition at line 230 of file mathlib.qc.

231{
232 return sqrt(-1);
233}

References sqrt().

Referenced by lgamma(), and nextafter().

◆ nearbyint()

float nearbyint ( float e)

Definition at line 199 of file mathlib.qc.

200{
201 return rint(e);
202}
float rint(float f)

References rint().

◆ nextafter()

float nextafter ( float e,
float f )

Definition at line 234 of file mathlib.qc.

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 nextafter(float e, float f)
Definition mathlib.qc:234

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

Referenced by nextafter(), and nexttoward().

◆ nexttoward()

float nexttoward ( float e,
float f )

Definition at line 255 of file mathlib.qc.

256{
257 return nextafter(e, f);
258}

References nextafter().

◆ 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.

195{
196 return e - f * floor(e / f);
197}

References floor().

Referenced by PRECACHE(), and tubasound().

◆ remainder()

float remainder ( float e,
float f )

Definition at line 212 of file mathlib.qc.

213{
214 return e - f * rint(e / f);
215}

References rint().

Referenced by func_pendulum_controller_think(), and IsMoveInDirection().

◆ remquo()

vector remquo ( float e,
float f )

Definition at line 216 of file mathlib.qc.

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}

References rint(), and vector.

◆ scalbn()

float scalbn ( float e,
int n )

Definition at line 127 of file mathlib.qc.

128{
129 return e * pow(2, n);
130}

References pow.

◆ signbit()

bool signbit ( float e)

Definition at line 43 of file mathlib.qc.

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

Referenced by trigger_push_velocity_calculatevelocity().

◆ sinh()

float sinh ( float e)

Definition at line 64 of file mathlib.qc.

65{
66 return 0.5 * (exp(e) - exp(-e));
67}

References exp().

Referenced by tanh().

◆ tanh()

float tanh ( float e)

Definition at line 68 of file mathlib.qc.

69{
70 return sinh(e) / cosh(e);
71}
float sinh(float e)
Definition mathlib.qc:64
float cosh(float e)
Definition mathlib.qc:60

References cosh(), and sinh().

Referenced by ctf_CalculatePassVelocity().

◆ tgamma()

float tgamma ( float e)

Definition at line 179 of file mathlib.qc.

180{
181 vector v = lgamma(e);
182 return exp(v.x) * v.y;
183}

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

◆ trunc()

float trunc ( float e)

Definition at line 203 of file mathlib.qc.

204{
205 return (e>=0) ? floor(e) : ceil(e);
206}
float ceil(float f)

References ceil(), and floor().

Referenced by fmod(), and modf().

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

◆ 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(), and MUTATOR_HOOKFUNCTION().

◆ M_SQRT2

const float M_SQRT2 = 1.41421356237309504880

Definition at line 114 of file mathlib.qh.

Referenced by drawspritearrow(), and havocbot_movetogoal().