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)
 Returns mantissa as .x, exponent as .y.
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)
 Value in .x, sign in .y.
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)
 Fraction as .x, integer as .y.
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
 1/pi
const float M_2_PI = 0.63661977236758134308
 2/pi
const float M_2_SQRTPI = 1.12837916709551257390
 2/sqrt(pi)
const float M_E = 2.7182818284590452354
 e
const float M_LN10 = 2.30258509299404568402
 log_e 10
const float M_LN2 = 0.69314718055994530942
 log_e 2
const float M_LOG10E = 0.43429448190325182765
 log_10 e
const float M_LOG2E = 1.4426950408889634074
 log_2 e
const float M_PI_2 = 1.57079632679489661923
 pi/2
const float M_PI_4 = 0.78539816339744830962
 pi/4
const float M_SQRT1_2 = 0.70710678118654752440
 1/sqrt(2)
const float M_SQRT2 = 1.41421356237309504880
 sqrt(2)

Macro Definition Documentation

◆ M_PI

Function Documentation

◆ acosh()

float acosh ( float e)

Definition at line 45 of file mathlib.qc.

46{
47 return log(e + sqrt(e*e - 1));
48}
float log(float f)
float sqrt(float f)

References log(), and sqrt().

◆ asinh()

float asinh ( float e)

Definition at line 49 of file mathlib.qc.

50{
51 return log(e + sqrt(e*e + 1));
52}

References log(), and sqrt().

◆ atanh()

float atanh ( float e)

Definition at line 53 of file mathlib.qc.

54{
55 return 0.5 * log((1+e) / (1-e));
56}

References log().

◆ cbrt()

float cbrt ( float e)

Definition at line 129 of file mathlib.qc.

130{
131 return copysign(pow(fabs(e), (1.0/3.0)), e);
132}
#define pow(a, b)
Definition _all.inc:67
float copysign(float e, float f)
Definition mathlib.qc:220
float fabs(float f)

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

Referenced by solve_cubic_pq().

◆ copysign()

float copysign ( float e,
float f )

Definition at line 220 of file mathlib.qc.

221{
222 return fabs(e) * ((f>0) ? 1 : -1);
223}

References fabs().

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

◆ cosh()

float cosh ( float e)

Definition at line 57 of file mathlib.qc.

58{
59 return 0.5 * (exp(e) + exp(-e));
60}
float exp(float e)
Definition mathlib.qc:70

References exp().

Referenced by tanh().

◆ erf()

float erf ( float e)

Definition at line 138 of file mathlib.qc.

139{
140 // approximation taken from wikipedia
141 float f = e*e;
142 return copysign(sqrt(1 - exp(-f * (1.273239544735163 + 0.14001228868667 * f) / (1 + 0.14001228868667 * f))), e);
143}

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

Referenced by erfc().

◆ erfc()

float erfc ( float e)

Definition at line 144 of file mathlib.qc.

145{
146 return 1.0 - erf(e);
147}
float erf(float e)
Definition mathlib.qc:138

References erf().

◆ exp()

◆ exp2()

float exp2 ( float e)

Definition at line 74 of file mathlib.qc.

75{
76 return pow(2, e);
77}

References pow.

◆ expm1()

float expm1 ( float e)

Definition at line 78 of file mathlib.qc.

79{
80 return exp(e) - 1;
81}

References exp().

◆ fdim()

float fdim ( float e,
float f )

Definition at line 255 of file mathlib.qc.

256{
257 return max(e-f, 0);
258}
float max(float f,...)

References max().

◆ fma()

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

Definition at line 267 of file mathlib.qc.

268{
269 return e * f + g;
270}

◆ fmax()

float fmax ( float e,
float f )

Definition at line 259 of file mathlib.qc.

260{
261 return max(e, f);
262}

References max().

◆ fmin()

float fmin ( float e,
float f )

Definition at line 263 of file mathlib.qc.

264{
265 return min(e, f);
266}
float min(float f,...)

References min().

◆ fmod()

float fmod ( float e,
float f )

Definition at line 203 of file mathlib.qc.

204{
205 return e - f * trunc(e / f);
206}
float trunc(float e)
Definition mathlib.qc:198

References trunc().

Referenced by CSQCModel_Effects_Apply().

◆ fpclassify()

int fpclassify ( float e)

Definition at line 3 of file mathlib.qc.

4{
5 if (isnan(e))
6 return FP_NAN;
7 if (isinf(e))
8 return FP_INFINITE;
9 if (e == 0)
10 return FP_ZERO;
11 return FP_NORMAL;
12}
bool isinf(float e)
Definition mathlib.qc:17
bool isnan(float e)
Definition mathlib.qc:21
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)

Returns mantissa as .x, exponent as .y.

Definition at line 83 of file mathlib.qc.

84{
85 vector v;
86 v.z = 0;
87 v.y = ilogb(e) + 1;
88 v.x = e / pow(2, v.y);
89 return v;
90}
int ilogb(float e)
Definition mathlib.qc:91
vector
Definition self.qh:96

References ilogb(), pow, and vector.

◆ hypot()

float hypot ( float e,
float f )

Definition at line 133 of file mathlib.qc.

134{
135 return sqrt(e*e + f*f);
136}

References sqrt().

◆ ilogb()

int ilogb ( float e)

Definition at line 91 of file mathlib.qc.

92{
93 return floor(log2(fabs(e)));
94}
float log2(float e)
Definition mathlib.qc:111
float floor(float f)

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

Referenced by frexp().

◆ isfinite()

bool isfinite ( float e)

Definition at line 13 of file mathlib.qc.

14{
15 return !(isnan(e) || isinf(e));
16}

References isinf(), and isnan().

Referenced by isnormal(), and lgamma().

◆ isgreater()

int isgreater ( float e,
float f )

Definition at line 272 of file mathlib.qc.

273{
274 return e > f;
275}

◆ isgreaterequal()

int isgreaterequal ( float e,
float f )

Definition at line 276 of file mathlib.qc.

277{
278 return e >= f;
279}

◆ isinf()

bool isinf ( float e)

Definition at line 17 of file mathlib.qc.

18{
19 return (e != 0) && (e + e == e);
20}

Referenced by fpclassify(), and isfinite().

◆ isless()

int isless ( float e,
float f )

Definition at line 280 of file mathlib.qc.

281{
282 return e < f;
283}

◆ islessequal()

int islessequal ( float e,
float f )

Definition at line 284 of file mathlib.qc.

285{
286 return e <= f;
287}

◆ islessgreater()

int islessgreater ( float e,
float f )

Definition at line 288 of file mathlib.qc.

289{
290 return e < f || e > f;
291}

◆ isnan()

bool isnan ( float e)

Definition at line 21 of file mathlib.qc.

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

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

◆ isnormal()

bool isnormal ( float e)

Definition at line 36 of file mathlib.qc.

37{
38 return isfinite(e);
39}
bool isfinite(float e)
Definition mathlib.qc:13

References isfinite().

◆ isunordered()

int isunordered ( float e,
float f )

Definition at line 292 of file mathlib.qc.

293{
294 return !(e < f || e == f || e > f);
295}

◆ ldexp()

float ldexp ( float e,
int e )

Definition at line 95 of file mathlib.qc.

96{
97 return x * pow(2, e);
98}
v x
Definition ent_cs.qc:146

References pow, and x.

◆ lgamma()

vector lgamma ( float e)

Value in .x, sign in .y.

Definition at line 148 of file mathlib.qc.

149{
150 // TODO improve accuracy
151 if (!isfinite(e))
152 return fabs(e) * '1 0 0' + copysign(1, e) * '0 1 0';
153 if (e < 1 && e == floor(e))
154 return nan("gamma") * '1 1 1';
155 if (e < 0.1)
156 {
157 vector v = lgamma(1.0 - e);
158 // reflection formula:
159 // gamma(1-z) * gamma(z) = pi / sin(pi*z)
160 // lgamma(1-z) + lgamma(z) = log(pi) - log(sin(pi*z))
161 // sign of gamma(1-z) = sign of gamma(z) * sign of sin(pi*z)
162 v.z = sin(M_PI * e);
163 v.x = log(M_PI) - log(fabs(v.z)) - v.x;
164 if (v.z < 0)
165 v.y = -v.y;
166 v.z = 0;
167 return v;
168 }
169 if (e < 1.1)
170 return lgamma(e + 1) - log(e) * '1 0 0';
171 --e;
172 return (0.5 * log(2 * M_PI * e) + e * (log(e) - 1)) * '1 0 0' + '0 1 0';
173}
float nan(string tag)
Definition mathlib.qc:225
vector lgamma(float e)
Value in .x, sign in .y.
Definition mathlib.qc:148
#define M_PI
pi
Definition mathlib.qh:112
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 103 of file mathlib.qc.

104{
105 return log(e) * M_LOG10E;
106}
const float M_LOG10E
log_10 e
Definition mathlib.qh:107

References log(), and M_LOG10E.

◆ log1p()

float log1p ( float e)

Definition at line 107 of file mathlib.qc.

108{
109 return log(e + 1);
110}

References log().

◆ log2()

float log2 ( float e)

Definition at line 111 of file mathlib.qc.

112{
113 return log(e) * M_LOG2E;
114}
const float M_LOG2E
log_2 e
Definition mathlib.qh:106

References log(), and M_LOG2E.

Referenced by ilogb(), and logb().

◆ logb()

float logb ( float e)

Definition at line 115 of file mathlib.qc.

116{
117 return floor(log2(fabs(e)));
118}

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

◆ logn()

float logn ( float e,
float base )

Definition at line 99 of file mathlib.qc.

100{
101 return log(e) / log(base);
102}

References log().

Referenced by buff_Inferno_CalculateTime().

◆ modf()

vector modf ( float f)

Fraction as .x, integer as .y.

Definition at line 119 of file mathlib.qc.

120{
121 return '1 0 0' * (f - trunc(f)) + '0 1 0' * trunc(f);
122}

References trunc(), and vector.

◆ nan()

float nan ( string tag)

Definition at line 225 of file mathlib.qc.

226{
227 return sqrt(-1);
228}

References sqrt().

Referenced by lgamma(), and nextafter().

◆ nearbyint()

float nearbyint ( float e)

Definition at line 194 of file mathlib.qc.

195{
196 return rint(e);
197}
float rint(float f)

References rint().

◆ nextafter()

float nextafter ( float e,
float f )

Definition at line 229 of file mathlib.qc.

230{
231 // TODO very crude
232 if (e == f)
233 return nan("nextafter");
234 if (e > f)
235 return -nextafter(-e, -f);
236 // now we know that e < f
237 // so we need the next number > e
238 float d, a, b;
239 d = max(fabs(e), 0.00000000000000000000001);
240 a = e + d;
241 do
242 {
243 d *= 0.5;
244 b = a;
245 a = e + d;
246 }
247 while (a != e);
248 return b;
249}
float nextafter(float e, float f)
Definition mathlib.qc:229

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

Referenced by nextafter(), and nexttoward().

◆ nexttoward()

float nexttoward ( float e,
float f )

Definition at line 250 of file mathlib.qc.

251{
252 return nextafter(e, f);
253}

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 189 of file mathlib.qc.

190{
191 return e - f * floor(e / f);
192}

References floor().

Referenced by PRECACHE(), and tubasound().

◆ remainder()

float remainder ( float e,
float f )

Definition at line 207 of file mathlib.qc.

208{
209 return e - f * rint(e / f);
210}

References rint().

Referenced by func_pendulum_controller_think(), and IsMoveInDirection().

◆ remquo()

vector remquo ( float e,
float f )

Definition at line 211 of file mathlib.qc.

212{
213 vector v;
214 v.z = 0;
215 v.y = rint(e / f);
216 v.x = e - f * v.y;
217 return v;
218}

References rint(), and vector.

◆ scalbn()

float scalbn ( float e,
int n )

Definition at line 124 of file mathlib.qc.

125{
126 return e * pow(2, n);
127}

References pow.

◆ signbit()

bool signbit ( float e)

Definition at line 40 of file mathlib.qc.

41{
42 return (e < 0);
43}

Referenced by trigger_push_velocity_calculatevelocity().

◆ sinh()

float sinh ( float e)

Definition at line 61 of file mathlib.qc.

62{
63 return 0.5 * (exp(e) - exp(-e));
64}

References exp().

Referenced by tanh().

◆ tanh()

float tanh ( float e)

Definition at line 65 of file mathlib.qc.

66{
67 return sinh(e) / cosh(e);
68}
float sinh(float e)
Definition mathlib.qc:61
float cosh(float e)
Definition mathlib.qc:57

References cosh(), and sinh().

Referenced by ctf_CalculatePassVelocity().

◆ tgamma()

float tgamma ( float e)

Definition at line 174 of file mathlib.qc.

175{
176 vector v = lgamma(e);
177 return exp(v.x) * v.y;
178}

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

◆ trunc()

float trunc ( float e)

Definition at line 198 of file mathlib.qc.

199{
200 return (e>=0) ? floor(e) : ceil(e);
201}
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

1/pi

Definition at line 115 of file mathlib.qh.

◆ M_2_PI

const float M_2_PI = 0.63661977236758134308

2/pi

Definition at line 116 of file mathlib.qh.

◆ M_2_SQRTPI

const float M_2_SQRTPI = 1.12837916709551257390

2/sqrt(pi)

Definition at line 117 of file mathlib.qh.

◆ M_E

const float M_E = 2.7182818284590452354

e

Definition at line 105 of file mathlib.qh.

Referenced by colormapPaletteColor_(), and exp().

◆ M_LN10

const float M_LN10 = 2.30258509299404568402

log_e 10

Definition at line 109 of file mathlib.qh.

◆ M_LN2

const float M_LN2 = 0.69314718055994530942

log_e 2

Definition at line 108 of file mathlib.qh.

◆ M_LOG10E

const float M_LOG10E = 0.43429448190325182765

log_10 e

Definition at line 107 of file mathlib.qh.

Referenced by log10().

◆ M_LOG2E

const float M_LOG2E = 1.4426950408889634074

log_2 e

Definition at line 106 of file mathlib.qh.

Referenced by log2().

◆ M_PI_2

const float M_PI_2 = 1.57079632679489661923

pi/2

Definition at line 113 of file mathlib.qh.

Referenced by decompressShortVector(), HUD_Physics(), StrafeHUD_DrawTextIndicator(), and tubasound().

◆ M_PI_4

const float M_PI_4 = 0.78539816339744830962

pi/4

Definition at line 114 of file mathlib.qh.

◆ M_SQRT1_2

const float M_SQRT1_2 = 0.70710678118654752440

1/sqrt(2)

Definition at line 119 of file mathlib.qh.

Referenced by MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ M_SQRT2

const float M_SQRT2 = 1.41421356237309504880

sqrt(2)

Definition at line 118 of file mathlib.qh.

Referenced by drawspritearrow(), and havocbot_movetogoal().