1 /**
2     Bindings to C standard library math functions.
3 
4     Copyright:
5         Copyright © 2023-2025, Kitsunebi Games
6         Copyright © 2023-2025, Inochi2D Project
7     
8     License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
9     Authors:   Luna Nielsen
10 */
11 module nulib.c.math;
12 
13 extern(C) nothrow @nogc pure @safe:
14 
15 /**
16     Computes the absolute value for the given value.
17 
18     Params:
19         value = the value
20     
21     Returns:
22         The absolute value of $(D value)
23 */
24 extern double fabs(double value);
25 /// ditto
26 extern float fabsf(float value);
27 /// ditto
28 extern int labs(int value);
29 /// ditto
30 extern long llabs(long value);
31 
32 /**
33     Computes the remainder of the floating point division.
34 
35     Params:
36         x = The base
37         y = The divisor
38     
39     Returns:
40         The remainder of $(D x / y).
41 */
42 extern double fmod(double x, double y);
43 /// ditto
44 extern float fmodf(float x, float y);
45 
46 /**
47     Computes the remainder of the floating point division.
48 
49     Note:
50         As opposed to $(D fmod), the return value is $(B not)
51         guaranteed to be the same sign as $(D x).
52 
53     Params:
54         x = The base
55         y = The divisor
56     
57     Returns:
58         The remainder of $(D x / y).
59 */
60 extern double remainder(double x, double y);
61 /// ditto
62 extern float remainderf(float x, float y);
63 
64 /**
65     Computes the fused-multiply-add operation.
66 
67     Params:
68         x = value
69         y = value
70         z = value
71     
72     Returns:
73         The result of $(D (x * y) + z) as a fused operation.
74 */
75 extern double fma(double x, double y, double z);
76 /// ditto
77 extern float fmaf(float x, float y, float z);
78 
79 /**
80     Computes the positive difference between 2 values.
81 
82     Params:
83         x = value
84         y = value
85     
86     Returns:
87         The positive difference between $(D x) and $(D y).
88         If the result is negative, returns +0.
89 */
90 extern double fdim(double x, double y);
91 /// ditto
92 extern float fdimf(float x, float y);
93 
94 /**
95     Computes $(I e) raised to the given power.
96 
97     Params:
98         arg = The power to raise it by.
99     
100     Returns:
101         $(I e) raised to the power of $(D arg).
102 */
103 extern double exp(double arg);
104 /// ditto
105 extern float expf(float arg);
106 
107 /**
108     Computes $(I 2) raised to the given power.
109 
110     Params:
111         arg = The power to raise it by.
112     
113     Returns:
114         $(I 2) raised to the power of $(D arg).
115 */
116 extern double exp2(double arg);
117 /// ditto
118 extern float exp2f(float arg);
119 
120 /**
121     Computes $(I e) raised to the given power minus one.
122 
123     Params:
124         arg = The power to raise it by.
125     
126     Returns:
127         $(I e) raised to the power of $(D arg), subtracted by 1.
128 */
129 extern double expm1(double arg);
130 /// ditto
131 extern float expm1f(float arg);
132 
133 /**
134     Computes the natural (base-e) logarithm.
135 
136     Params:
137         arg = The value to compute the logarithm of
138     
139     Returns:
140         The natural base logarithm of $(D arg).
141 */
142 extern double log(double arg);
143 /// ditto
144 extern float logf(float arg);
145 
146 /**
147     Computes the common (base-10) logarithm.
148 
149     Params:
150         arg = The value to compute the logarithm of
151     
152     Returns:
153         The common base logarithm of $(D arg).
154 */
155 extern double log10(double arg);
156 /// ditto
157 extern float log10f(float arg);
158 
159 /**
160     Computes the binary (base-2) logarithm.
161 
162     Params:
163         arg = The value to compute the logarithm of
164     
165     Returns:
166         The base-2 logarithm of $(D arg).
167 */
168 extern double log2(double arg);
169 /// ditto
170 extern float log2f(float arg);
171 
172 /**
173     Computes a value raised to a given power.
174 
175     Params:
176         x = The base
177         y = The power
178     
179     Returns:
180         $(D x) raised to the power of $(D y)
181 */
182 extern double pow(double x, double y);
183 /// ditto
184 extern float powf(float x, float y);
185 
186 /**
187     Computes the square root of the given value.
188 
189     Params:
190         x = The value
191     
192     Returns:
193         The square root of $(D x).
194 */
195 extern double sqrt(double x);
196 /// ditto
197 extern float sqrtf(float x);
198 
199 /**
200     Computes the cube root of the given value.
201 
202     Params:
203         x = The value
204     
205     Returns:
206         The cube root of $(D x).
207 */
208 extern double cbrt(double x);
209 /// ditto
210 extern float cbrtf(float x);
211 
212 /**
213     Computes the square root of the sum of the squares of the 
214     given values.
215 
216     Params:
217         x = value
218         y = value
219     
220     Returns:
221         The equivalent of $(D sqrt(pow(x, 2) + pow(y, 2))).
222 */
223 extern double hypot(double x, double y);
224 /// ditto
225 extern float hypotf(float x, float y);
226 
227 /**
228     Computes sine of the given value.
229 
230     Params:
231         x = The value
232     
233     Returns:
234         The sine of $(D x).
235 */
236 extern double sin(double x);
237 /// ditto
238 extern float sinf(float x);
239 
240 /**
241     Computes cosine of the given value.
242 
243     Params:
244         x = The value
245     
246     Returns:
247         The cosine of $(D x).
248 */
249 extern double cos(double x);
250 /// ditto
251 extern float cosf(float x);
252 
253 /**
254     Computes tangent of the given value.
255 
256     Params:
257         x = The value
258     
259     Returns:
260         The tangent of $(D x).
261 */
262 extern double tan(double x);
263 /// ditto
264 extern float tanf(float x);
265 
266 /**
267     Computes arc-sine of the given value.
268 
269     Params:
270         x = The value
271     
272     Returns:
273         The arc-sine of $(D x).
274 */
275 extern double asin(double x);
276 /// ditto
277 extern float asinf(float x);
278 
279 /**
280     Computes arc-cosine of the given value.
281 
282     Params:
283         x = The value
284     
285     Returns:
286         The arc-cosine of $(D x).
287 */
288 extern double acos(double x);
289 /// ditto
290 extern float acosf(float x);
291 
292 /**
293     Computes arc-tangent of the given value.
294 
295     Params:
296         x = The value
297     
298     Returns:
299         The arc-tangent of $(D x).
300 */
301 extern double atan(double x);
302 /// ditto
303 extern float atanf(float x);
304 
305 /**
306     Computes arc-tangent of the given value, using signs to determine quadrant.
307 
308     Params:
309         y = value
310         x = value
311     
312     Returns:
313         The arc-tangent of $(D y / x).
314 */
315 extern double atan2(double y, double x);
316 /// ditto
317 extern float atan2f(float y, float x);
318 
319 /**
320     Computes hyperbolic sine of the given value.
321 
322     Params:
323         x = The value
324     
325     Returns:
326         The hyperbolic sine of $(D x).
327 */
328 extern double sinh(double x);
329 /// ditto
330 extern float sinhf(float x);
331 
332 /**
333     Computes hyperbolic cosine of the given value.
334 
335     Params:
336         x = The value
337     
338     Returns:
339         The hyperbolic cosine of $(D x).
340 */
341 extern double cosh(double x);
342 /// ditto
343 extern float coshf(float x);
344 
345 /**
346     Computes hyperbolic tangent of the given value.
347 
348     Params:
349         x = The value
350     
351     Returns:
352         The hyperbolic tangent of $(D x).
353 */
354 extern double tanh(double x);
355 /// ditto
356 extern float tanhf(float x);
357 
358 /**
359     Computes hyperbolic arc-sine of the given value.
360 
361     Params:
362         x = The value
363     
364     Returns:
365         The hyperbolic arc-sine of $(D x).
366 */
367 extern double asinh(double x);
368 /// ditto
369 extern float asinhf(float x);
370 
371 /**
372     Computes hyperbolic arc-cosine of the given value.
373 
374     Params:
375         x = The value
376     
377     Returns:
378         The hyperbolic arc-cosine of $(D x).
379 */
380 extern double acosh(double x);
381 /// ditto
382 extern float acoshf(float x);
383 
384 /**
385     Computes hyperbolic arc-tangent of the given value.
386 
387     Params:
388         x = The value
389     
390     Returns:
391         The hyperbolic arc-tangent of $(D x).
392 */
393 extern double atanh(double x);
394 /// ditto
395 extern float atanhf(float x);
396 
397 /**
398     Computes the error function of the given value.
399 
400     Params:
401         x = The value
402     
403     Returns:
404         The error function of $(D x).
405 
406     See_Also:
407         $(LINK2 https://en.wikipedia.org/wiki/Error_function, Error Function on Wikipedia)
408 */
409 extern double erf(double x);
410 /// ditto
411 extern float erff(float x);
412 
413 /**
414     Computes the complementary error function of the given value.
415 
416     Params:
417         x = The value
418     
419     Returns:
420         The complementary error function of $(D x).
421 
422     See_Also:
423         $(LINK2 https://en.wikipedia.org/wiki/Error_function#Complementary_error_function, Error Function on Wikipedia)
424 */
425 extern double erfc(double x);
426 /// ditto
427 extern float erfcf(float x);
428 
429 /**
430     Computes the gamma function of the given value.
431 
432     Params:
433         x = The value
434     
435     Returns:
436         The gamma function of $(D x).
437 
438     See_Also:
439         $(LINK2 https://en.wikipedia.org/wiki/Gamma_function, Gamma Function on Wikipedia)
440 */
441 extern double tgamma(double x);
442 /// ditto
443 extern float tgammaf(float x);
444 
445 /**
446     Computes the natural (base-e) logarithm of the gamma function 
447     of the given value.
448 
449     Params:
450         x = The value
451     
452     Returns:
453         The natural logarithm of the gamma function of $(D x).
454 
455     See_Also:
456         $(LINK2 https://en.wikipedia.org/wiki/Gamma_function, Gamma Function on Wikipedia)
457 */
458 extern double lgamma(double x);
459 /// ditto
460 extern float lgammaf(float x);
461 
462 /**
463     Computes the nearest integer value greater than the given value.
464 
465     Params:
466         x = The value
467     
468     Returns:
469         The nearest integer value greater than $(D x).
470 */
471 extern double ceil(double x);
472 /// ditto
473 extern float ceilf(float x);
474 
475 /**
476     Computes the nearest integer value lower than the given value.
477 
478     Params:
479         x = The value
480     
481     Returns:
482         The nearest integer value lower than $(D x).
483 */
484 extern double floor(double x);
485 /// ditto
486 extern float floorf(float x);
487 
488 /**
489     Computes the nearest integer value lower in magnitude than
490     the given value.
491 
492     Params:
493         x = The value
494     
495     Returns:
496         The nearest integer value lower in magnitude than $(D x).
497 */
498 extern double trunc(double x);
499 /// ditto
500 extern float truncf(float x);
501 
502 /**
503     Computes the nearest integer value, rounded away from 0.
504 
505     Params:
506         x = The value
507     
508     Returns:
509         The nearest integer value to $(D x).
510 */
511 extern double round(double x);
512 /// ditto
513 extern float roundf(float x);