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 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:224
float fabs(float f)

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

Referenced by solve_cubic_pq().

◆ copysign()

float copysign ( float e,
float f )

Definition at line 224 of file mathlib.qc.

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

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 = 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: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 259 of file mathlib.qc.

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

References max().

◆ fma()

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

Definition at line 271 of file mathlib.qc.

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

◆ fmax()

float fmax ( float e,
float f )

Definition at line 263 of file mathlib.qc.

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

References max().

◆ fmin()

float fmin ( float e,
float f )

Definition at line 267 of file mathlib.qc.

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

References min().

◆ fmod()

float fmod ( float e,
float f )

Definition at line 207 of file mathlib.qc.

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

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

277{
278 return e > f;
279}

◆ isgreaterequal()

int isgreaterequal ( float e,
float f )

Definition at line 280 of file mathlib.qc.

281{
282 return e >= f;
283}

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

285{
286 return e < f;
287}

◆ islessequal()

int islessequal ( float e,
float f )

Definition at line 288 of file mathlib.qc.

289{
290 return e <= f;
291}

◆ islessgreater()

int islessgreater ( float e,
float f )

Definition at line 292 of file mathlib.qc.

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

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

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

◆ ldexp()

float ldexp ( float e,
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 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 = lgamma(1.0 - e);
162 // reflection formula:
163 // gamma(1-z) * gamma(z) = pi / sin(pi*z)
164 // lgamma(1-z) + lgamma(z) = log(pi) - log(sin(pi*z))
165 // sign of gamma(1-z) = sign of gamma(z) * sign of sin(pi*z)
166 v.z = sin(M_PI * e);
167 v.x = log(M_PI) - log(fabs(v.z)) - v.x;
168 if(v.z < 0)
169 v.y = -v.y;
170 v.z = 0;
171 return v;
172 }
173 if(e < 1.1)
174 return lgamma(e + 1) - log(e) * '1 0 0';
175 --e;
176 return (0.5 * log(2 * M_PI * e) + e * (log(e) - 1)) * '1 0 0' + '0 1 0';
177}
float nan(string tag)
Definition mathlib.qc:229
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 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 229 of file mathlib.qc.

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

References sqrt().

Referenced by lgamma(), and nextafter().

◆ nearbyint()

float nearbyint ( float e)

Definition at line 198 of file mathlib.qc.

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

References rint().

◆ nextafter()

float nextafter ( float e,
float f )

Definition at line 233 of file mathlib.qc.

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

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

Referenced by nextafter(), and nexttoward().

◆ nexttoward()

float nexttoward ( float e,
float f )

Definition at line 254 of file mathlib.qc.

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

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

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

References floor().

Referenced by PRECACHE(), and tubasound().

◆ remainder()

float remainder ( float e,
float f )

Definition at line 211 of file mathlib.qc.

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

References rint().

Referenced by func_pendulum_controller_think(), and IsMoveInDirection().

◆ remquo()

vector remquo ( float e,
float f )

Definition at line 215 of file mathlib.qc.

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

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

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

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

◆ trunc()

float trunc ( float e)

Definition at line 202 of file mathlib.qc.

203{
204 return (e>=0) ? floor(e) : ceil(e);
205}
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().