Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
mathlib.qc File Reference
#include "mathlib.qh"
Include dependency graph for mathlib.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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 x, 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)

Function Documentation

◆ acosh()

float acosh ( float e)

Definition at line 49 of file mathlib.qc.

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

References log(), and sqrt().

◆ asinh()

float asinh ( float e)

Definition at line 53 of file mathlib.qc.

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

References log(), and sqrt().

◆ atanh()

float atanh ( float e)

Definition at line 57 of file mathlib.qc.

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

References log().

◆ cbrt()

float cbrt ( float e)

Definition at line 133 of file mathlib.qc.

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

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

Referenced by solve_cubic_pq().

◆ copysign()

float copysign ( float e,
float f )

Definition at line 226 of file mathlib.qc.

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

References fabs().

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

◆ cosh()

float cosh ( float e)

Definition at line 61 of file mathlib.qc.

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

References exp().

Referenced by tanh().

◆ erf()

float erf ( float e)

Definition at line 142 of file mathlib.qc.

143{
144 // approximation taken from wikipedia
145 float f;
146 f = e*e;
147 return copysign(sqrt(1 - exp(-f * (1.273239544735163 + 0.14001228868667 * f) / (1 + 0.14001228868667 * f))), e);
148}

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

Referenced by erfc().

◆ erfc()

float erfc ( float e)

Definition at line 149 of file mathlib.qc.

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

References erf().

◆ exp()

◆ exp2()

float exp2 ( float e)

Definition at line 78 of file mathlib.qc.

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

References pow.

◆ expm1()

float expm1 ( float e)

Definition at line 82 of file mathlib.qc.

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

References exp().

◆ fdim()

float fdim ( float e,
float f )

Definition at line 261 of file mathlib.qc.

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

References max().

◆ fma()

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

Definition at line 273 of file mathlib.qc.

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

◆ fmax()

float fmax ( float e,
float f )

Definition at line 265 of file mathlib.qc.

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

References max().

◆ fmin()

float fmin ( float e,
float f )

Definition at line 269 of file mathlib.qc.

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

References min().

◆ fmod()

float fmod ( float e,
float f )

Definition at line 209 of file mathlib.qc.

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

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

88{
89 vector v;
90 v.z = 0;
91 v.y = ilogb(e) + 1;
92 v.x = e / pow(2, v.y);
93 return v;
94}
int ilogb(float e)
Definition mathlib.qc:95
vector
Definition self.qh:92

References ilogb(), pow, and vector.

◆ hypot()

float hypot ( float e,
float f )

Definition at line 137 of file mathlib.qc.

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

References sqrt().

◆ ilogb()

int ilogb ( float e)

Definition at line 95 of file mathlib.qc.

96{
97 return floor(log2(fabs(e)));
98}
float log2(float e)
Definition mathlib.qc:115
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 278 of file mathlib.qc.

279{
280 return e > f;
281}

◆ isgreaterequal()

int isgreaterequal ( float e,
float f )

Definition at line 282 of file mathlib.qc.

283{
284 return e >= f;
285}

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

287{
288 return e < f;
289}

◆ islessequal()

int islessequal ( float e,
float f )

Definition at line 290 of file mathlib.qc.

291{
292 return e <= f;
293}

◆ islessgreater()

int islessgreater ( float e,
float f )

Definition at line 294 of file mathlib.qc.

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

◆ 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 // bones_was_here: fixed in 0.8.5 and later.
34
35 // Negative NaN ("-nan") is much more common but plain "nan" can be created by negating *some* -nans so we need to check both.
36 // DP's QCVM and GMQCC's QCVM behave differently - one needs ftos(-(0.0 / 0.0)), the other ftos(-sqrt(-1)).
37// string s = ftos(e);
38// return s == "nan" || s == "-nan";
39}

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

◆ isnormal()

bool isnormal ( float e)

Definition at line 40 of file mathlib.qc.

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

References isfinite().

◆ isunordered()

int isunordered ( float e,
float f )

Definition at line 298 of file mathlib.qc.

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

◆ ldexp()

float ldexp ( float x,
int e )

Definition at line 99 of file mathlib.qc.

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

References pow.

◆ lgamma()

vector lgamma ( float e)

Definition at line 153 of file mathlib.qc.

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

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

References log(), and M_LOG10E.

◆ log1p()

float log1p ( float e)

Definition at line 111 of file mathlib.qc.

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

References log().

◆ log2()

float log2 ( float e)

Definition at line 115 of file mathlib.qc.

116{
117 return log(e) * M_LOG2E;
118}
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 119 of file mathlib.qc.

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

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

◆ logn()

float logn ( float e,
float base )

Definition at line 103 of file mathlib.qc.

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

References log().

Referenced by buff_Inferno_CalculateTime().

◆ modf()

vector modf ( float f)

Definition at line 123 of file mathlib.qc.

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

References trunc(), and vector.

◆ nan()

float nan ( string tag)

Definition at line 231 of file mathlib.qc.

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

References sqrt().

Referenced by lgamma(), and nextafter().

◆ nearbyint()

float nearbyint ( float e)

Definition at line 200 of file mathlib.qc.

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

References rint().

◆ nextafter()

float nextafter ( float e,
float f )

Definition at line 235 of file mathlib.qc.

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

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

Referenced by nextafter(), and nexttoward().

◆ nexttoward()

float nexttoward ( float e,
float f )

Definition at line 256 of file mathlib.qc.

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

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

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

References floor().

Referenced by PRECACHE(), and tubasound().

◆ remainder()

float remainder ( float e,
float f )

Definition at line 213 of file mathlib.qc.

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

References rint().

Referenced by func_pendulum_controller_think(), and IsMoveInDirection().

◆ remquo()

vector remquo ( float e,
float f )

Definition at line 217 of file mathlib.qc.

218{
219 vector v;
220 v.z = 0;
221 v.y = rint(e / f);
222 v.x = e - f * v.y;
223 return v;
224}

References rint(), and vector.

◆ scalbn()

float scalbn ( float e,
int n )

Definition at line 128 of file mathlib.qc.

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

References pow.

◆ signbit()

bool signbit ( float e)

Definition at line 44 of file mathlib.qc.

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

Referenced by trigger_push_velocity_calculatevelocity().

◆ sinh()

float sinh ( float e)

Definition at line 65 of file mathlib.qc.

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

References exp().

Referenced by tanh().

◆ tanh()

float tanh ( float e)

Definition at line 69 of file mathlib.qc.

70{
71 return sinh(e) / cosh(e);
72}
float sinh(float e)
Definition mathlib.qc:65
float cosh(float e)
Definition mathlib.qc:61

References cosh(), and sinh().

Referenced by ctf_CalculatePassVelocity().

◆ tgamma()

float tgamma ( float e)

Definition at line 180 of file mathlib.qc.

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

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

◆ trunc()

float trunc ( float e)

Definition at line 204 of file mathlib.qc.

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

References ceil(), and floor().

Referenced by fmod(), and modf().