3 @brief mathematical algorithm library
14 @addtogroup a_math mathematical algorithm library
19 #define A_E 2.71828182845904523536
20 /*! \f$ \log_{2}{e}=\frac{1}{\ln{2}} \f$ */
21 #define A_LOG2E 1.44269504088896340736
22 /*! \f$ \lg{e}=\frac{1}{\ln{2}+\ln{5}} \f$ */
23 #define A_LOG10E 0.434294481903251827651
25 #define A_LN2 0.693147180559945309417
26 /*! \f$ \frac{1}{\ln{2}} \f$ */
27 #define A_LN1_2 3.32192809488736218171
28 /*! \f$ \ln{10} \f$ */
29 #define A_LN10 2.30258509299404568402
30 /*! \f$ \frac{1}{\ln{10}} \f$ */
31 #define A_LN1_10 0.434294481903251827651
33 #define A_PI 3.14159265358979323846
35 #define A_TAU 6.28318530717958647693
36 /*! \f$ \frac{\pi}{2} \f$ */
37 #define A_PI_2 1.57079632679489661923
38 /*! \f$ \frac{\pi}{4} \f$ */
39 #define A_PI_4 0.785398163397448309616
40 /*! \f$ \frac{1}{\pi} \f$ */
41 #define A_1_PI 0.318309886183790671538
42 /*! \f$ \frac{2}{\pi} \f$ */
43 #define A_2_PI 0.636619772367581343076
44 /*! \f$ \frac{1}{2\pi} \f$ */
45 #define A_1_TAU 0.159154943091895335769
46 /*! \f$ \frac{2}{\sqrt{\pi}} \f$ */
47 #define A_2_SQRTPI 1.12837916709551257390
48 /*! \f$ \sqrt{2} \f$ */
49 #define A_SQRT2 1.41421356237309504880
50 /*! \f$ \frac{1}{\sqrt{2}}=\frac{\sqrt{2}}{2} \f$ */
51 #define A_SQRT1_2 0.707106781186547524401
52 /*! \f$ \sqrt{3} \f$ */
53 #define A_SQRT3 1.73205080756887729352
54 /*! \f$ \frac{1}{\sqrt{3}}=\frac{\sqrt{3}}{3} \f$ */
55 #define A_SQRT1_3 0.57735026918962576450
57 #if defined(__cplusplus)
59 #endif /* __cplusplus */
62 @brief reciprocal of square-root, \f$ \frac{1}{\sqrt{x}} \f$
63 @details http://en.wikipedia.org/wiki/Fast_inverse_square_root
64 @param[in] x independent variable
65 @return calculated result
67 A_EXTERN a_f32
a_f32_rsqrt(a_f32 x
);
68 A_EXTERN a_f64
a_f64_rsqrt(a_f64 x
);
71 @brief square root of an unsigned integer
72 @param[in] x independent variable
73 @return calculated result
75 A_EXTERN a_u16
a_u32_sqrt(a_u32 x
);
76 A_EXTERN a_u32
a_u64_sqrt(a_u64 x
);
78 #if defined(__cplusplus)
80 #endif /* __cplusplus */
82 #define a_f32_modf A_F32_F(modf)
83 #define a_f32_frexp A_F32_F(frexp)
84 #define a_f32_ldexp A_F32_F(ldexp)
85 #define a_f32_scalbn A_F32_F(scalbn)
86 #define a_f32_scalbln A_F32_F(scalbln)
87 #define a_f32_nextafter A_F32_F(nextafter)
88 #define a_f32_nexttoward A_F32_F(nexttoward)
89 #define a_f32_copysign A_F32_F(copysign)
91 #define a_f32_ma A_F32_F(fma)
92 #define a_f32_nan A_F32_F(nan)
93 #define a_f32_abs A_F32_F(fabs)
94 #define a_f32_mod A_F32_F(fmod)
95 #define a_f32_max A_F32_F(fmax)
96 #define a_f32_min A_F32_F(fmin)
97 #define a_f32_dim A_F32_F(fdim)
98 #define a_f32_remquo A_F32_F(remquo)
99 #define a_f32_remainder A_F32_F(remainder)
101 #define a_f32_exp A_F32_F(exp)
102 #define a_f32_exp2 A_F32_F(exp2)
103 #define a_f32_expm1 A_F32_F(expm1)
105 #define a_f32_log A_F32_F(log)
106 #define a_f32_logb A_F32_F(logb)
107 #define a_f32_log2 A_F32_F(log2)
108 #define a_f32_log10 A_F32_F(log10)
109 #define a_f32_log1p A_F32_F(log1p)
110 #define a_f32_ilogb A_F32_F(ilogb)
112 #define a_f32_pow A_F32_F(pow)
113 #define a_f32_sqrt A_F32_F(sqrt)
114 #define a_f32_cbrt A_F32_F(cbrt)
115 #define a_f32_hypot A_F32_F(hypot)
117 #define a_f32_sin A_F32_F(sin)
118 #define a_f32_cos A_F32_F(cos)
119 #define a_f32_tan A_F32_F(tan)
120 #define a_f32_asin A_F32_F(asin)
121 #define a_f32_acos A_F32_F(acos)
122 #define a_f32_atan A_F32_F(atan)
123 #define a_f32_atan2 A_F32_F(atan2)
125 #define a_f32_sinh A_F32_F(sinh)
126 #define a_f32_cosh A_F32_F(cosh)
127 #define a_f32_tanh A_F32_F(tanh)
128 #define a_f32_asinh A_F32_F(asinh)
129 #define a_f32_acosh A_F32_F(acosh)
130 #define a_f32_atanh A_F32_F(atanh)
132 #define a_f32_erf A_F32_F(erf)
133 #define a_f32_erfc A_F32_F(erfc)
134 #define a_f32_tgamma A_F32_F(tgamma)
135 #define a_f32_lgamma A_F32_F(lgamma)
137 #define a_f32_ceil A_F32_F(ceil)
138 #define a_f32_floor A_F32_F(floor)
139 #define a_f32_trunc A_F32_F(trunc)
140 #define a_f32_round A_F32_F(round)
141 #define a_f32_lround A_F32_F(lround)
142 #define a_f32_llround A_F32_F(llround)
143 #define a_f32_nearbyint A_F32_F(nearbyint)
144 #define a_f32_rint A_F32_F(rint)
145 #define a_f32_lrintt A_F32_F(lrint)
146 #define a_f32_llrintt A_F32_F(llrint)
148 #define a_f64_modf A_F64_F(modf)
149 #define a_f64_frexp A_F64_F(frexp)
150 #define a_f64_ldexp A_F64_F(ldexp)
151 #define a_f64_scalbn A_F64_F(scalbn)
152 #define a_f64_scalbln A_F64_F(scalbln)
153 #define a_f64_nextafter A_F64_F(nextafter)
154 #define a_f64_nexttoward A_F64_F(nexttoward)
155 #define a_f64_copysign A_F64_F(copysign)
157 #define a_f64_ma A_F64_F(fma)
158 #define a_f64_nan A_F64_F(nan)
159 #define a_f64_abs A_F64_F(fabs)
160 #define a_f64_mod A_F64_F(fmod)
161 #define a_f64_max A_F64_F(fmax)
162 #define a_f64_min A_F64_F(fmin)
163 #define a_f64_dim A_F64_F(fdim)
164 #define a_f64_remquo A_F64_F(remquo)
165 #define a_f64_remainder A_F64_F(remainder)
167 #define a_f64_exp A_F64_F(exp)
168 #define a_f64_exp2 A_F64_F(exp2)
169 #define a_f64_expm1 A_F64_F(expm1)
171 #define a_f64_log A_F64_F(log)
172 #define a_f64_logb A_F64_F(logb)
173 #define a_f64_log2 A_F64_F(log2)
174 #define a_f64_log10 A_F64_F(log10)
175 #define a_f64_log1p A_F64_F(log1p)
176 #define a_f64_ilogb A_F64_F(ilogb)
178 #define a_f64_pow A_F64_F(pow)
179 #define a_f64_sqrt A_F64_F(sqrt)
180 #define a_f64_cbrt A_F64_F(cbrt)
181 #define a_f64_hypot A_F64_F(hypot)
183 #define a_f64_sin A_F64_F(sin)
184 #define a_f64_cos A_F64_F(cos)
185 #define a_f64_tan A_F64_F(tan)
186 #define a_f64_asin A_F64_F(asin)
187 #define a_f64_acos A_F64_F(acos)
188 #define a_f64_atan A_F64_F(atan)
189 #define a_f64_atan2 A_F64_F(atan2)
191 #define a_f64_sinh A_F64_F(sinh)
192 #define a_f64_cosh A_F64_F(cosh)
193 #define a_f64_tanh A_F64_F(tanh)
194 #define a_f64_asinh A_F64_F(asinh)
195 #define a_f64_acosh A_F64_F(acosh)
196 #define a_f64_atanh A_F64_F(atanh)
198 #define a_f64_erf A_F64_F(erf)
199 #define a_f64_erfc A_F64_F(erfc)
200 #define a_f64_tgamma A_F64_F(tgamma)
201 #define a_f64_lgamma A_F64_F(lgamma)
203 #define a_f64_ceil A_F64_F(ceil)
204 #define a_f64_floor A_F64_F(floor)
205 #define a_f64_trunc A_F64_F(trunc)
206 #define a_f64_round A_F64_F(round)
207 #define a_f64_lround A_F64_F(lround)
208 #define a_f64_llround A_F64_F(llround)
209 #define a_f64_nearbyint A_F64_F(nearbyint)
210 #define a_f64_rint A_F64_F(rint)
211 #define a_f64_lrintt A_F64_F(lrint)
212 #define a_f64_llrintt A_F64_F(llrint)
218 @addtogroup a_float floating-point number
223 #define A_FLOAT_E A_FLOAT_C(A_E)
224 /*! \f$ \log_{2}{e}=\frac{1}{\ln{2}} \f$ */
225 #define A_FLOAT_LOG2E A_FLOAT_C(A_LOG2E)
226 /*! \f$ \lg{e}=\frac{1}{\ln{2}+\ln{5}} \f$ */
227 #define A_FLOAT_LOG10E A_FLOAT_C(A_LOG10E)
228 /*! \f$ \ln{2} \f$ */
229 #define A_FLOAT_LN2 A_FLOAT_C(A_LN2)
230 /*! \f$ \frac{1}{\ln{2}} \f$ */
231 #define A_FLOAT_LN1_2 A_FLOAT_C(A_LN1_2)
232 /*! \f$ \ln{10} \f$ */
233 #define A_FLOAT_LN10 A_FLOAT_C(A_LN10)
234 /*! \f$ \frac{1}{\ln{10}} \f$ */
235 #define A_FLOAT_LN1_10 A_FLOAT_C(A_LN1_10)
237 #define A_FLOAT_PI A_FLOAT_C(A_PI)
239 #define A_FLOAT_TAU A_FLOAT_C(A_TAU)
240 /*! \f$ \frac{\pi}{2} \f$ */
241 #define A_FLOAT_PI_2 A_FLOAT_C(A_PI_2)
242 /*! \f$ \frac{\pi}{4} \f$ */
243 #define A_FLOAT_PI_4 A_FLOAT_C(A_PI_4)
244 /*! \f$ \frac{1}{\pi} \f$ */
245 #define A_FLOAT_1_PI A_FLOAT_C(A_1_PI)
246 /*! \f$ \frac{2}{\pi} \f$ */
247 #define A_FLOAT_2_PI A_FLOAT_C(A_2_PI)
248 /*! \f$ \frac{1}{2\pi} \f$ */
249 #define A_FLOAT_1_TAU A_FLOAT_C(A_1_TAU)
250 /*! \f$ \frac{2}{\sqrt{\pi}} \f$ */
251 #define A_FLOAT_2_SQRTPI A_FLOAT_C(A_2_SQRTPI)
252 /*! \f$ \sqrt{2} \f$ */
253 #define A_FLOAT_SQRT2 A_FLOAT_C(A_SQRT2)
254 /*! \f$ \frac{1}{\sqrt{2}}=\frac{\sqrt{2}}{2} \f$ */
255 #define A_FLOAT_SQRT1_2 A_FLOAT_C(A_SQRT1_2)
256 /*! \f$ \sqrt{3} \f$ */
257 #define A_FLOAT_SQRT3 A_FLOAT_C(A_SQRT3)
258 /*! \f$ \frac{1}{\sqrt{3}}=\frac{\sqrt{3}}{3} \f$ */
259 #define A_FLOAT_SQRT1_3 A_FLOAT_C(A_SQRT1_3)
261 #if defined(__cplusplus)
263 #endif /* __cplusplus */
265 A_EXTERN a_float
a_float_asinh(a_float x
);
266 A_EXTERN a_float
a_float_acosh(a_float x
);
267 A_EXTERN a_float
a_float_atanh(a_float x
);
268 A_EXTERN a_float
a_float_expm1(a_float x
);
269 A_EXTERN a_float
a_float_log1p(a_float x
);
270 A_EXTERN a_float
a_float_atan2(a_float x
, a_float y
);
271 A_EXTERN a_float
a_float_hypot(a_float x
, a_float y
);
272 A_EXTERN a_float
a_float_hypot3(a_float x
, a_float y
, a_float z
);
275 @brief calculate the sum of a float array
276 @param[in] p points to a float array
277 @param[in] n number of a float array
278 @return sum of a float array
280 A_EXTERN a_float
a_float_sum(a_float
const *p
, a_size n
);
283 @brief calculate the absolute sum of a float array
284 @param[in] p points to a float array
285 @param[in] n number of a float array
286 @return absolute sum of a float array
288 A_EXTERN a_float
a_float_sum1(a_float
const *p
, a_size n
);
291 @brief calculate the sum of squares of a float array
292 @param[in] p points to a float array
293 @param[in] n number of a float array
294 @return sum of squares of a float array
296 A_EXTERN a_float
a_float_sum2(a_float
const *p
, a_size n
);
299 @brief calculate the mean of a float array
300 @param[in] p points to a float array
301 @param[in] n number of a float array
302 @return mean of a float array
304 A_EXTERN a_float
a_float_mean(a_float
const *p
, a_size n
);
307 @brief swap two different a_float blocks of the same size
308 @param[in,out] lhs points to a_float block on the left
309 @param[in,out] rhs points to a_float block on the right
310 @param[in] n the number of a_float block being swapped
312 A_EXTERN
A_NONULL((1, 2)) void a_float_swap(a_float
*lhs
, a_float
*rhs
, a_size n
);
315 @brief push an element into the front of a float array
316 @param[in] p points to a float array
317 @param[in] n number of a float array
320 A_EXTERN
void a_float_push_fore(a_float
*p
, a_size n
, a_float x
);
323 @brief push an element into the end of a float array
324 @param[in] p points to a float array
325 @param[in] n number of a float array
328 A_EXTERN
void a_float_push_back(a_float
*p
, a_size n
, a_float x
);
331 @brief push the elements into the front of a float array
332 @param[in] block_p points to a float array
333 @param[in] block_n number of a float array
334 @param[in] cache_p points to a cache array
335 @param[in] cache_n number of a cache array
337 A_EXTERN
void a_float_push_fore_(a_float
*block_p
, a_size block_n
,
338 a_float
const *cache_p
, a_size cache_n
);
341 @brief push the elements into the end of a float array
342 @param[in] block_p points to a float array
343 @param[in] block_n number of a float array
344 @param[in] cache_p points to a cache array
345 @param[in] cache_n number of a cache array
347 A_EXTERN
void a_float_push_back_(a_float
*block_p
, a_size block_n
,
348 a_float
const *cache_p
, a_size cache_n
);
351 @brief roll forward the elements of a float array circularly
352 @param[in] p points to a float array
353 @param[in] n number of a float array
355 A_EXTERN
void a_float_roll_fore(a_float
*p
, a_size n
);
358 @brief roll backward the elements of a float array circularly
359 @param[in] p points to a float array
360 @param[in] n number of a float array
362 A_EXTERN
void a_float_roll_back(a_float
*p
, a_size n
);
365 @brief roll forward the elements of a float array circularly
366 @param[in] block_p points to a float array
367 @param[in] block_n number of a float array
368 @param[in] shift_p points to a shift array
369 @param[in] shift_n number of a shift array
371 A_EXTERN
void a_float_roll_fore_(a_float
*block_p
, a_size block_n
,
372 a_float
*shift_p
, a_size shift_n
);
375 @brief roll backward the elements of a float array circularly
376 @param[in] block_p points to a float array
377 @param[in] block_n number of a float array
378 @param[in] shift_p points to a shift array
379 @param[in] shift_n number of a shift array
381 A_EXTERN
void a_float_roll_back_(a_float
*block_p
, a_size block_n
,
382 a_float
*shift_p
, a_size shift_n
);
384 #if defined(__cplusplus)
386 #endif /* __cplusplus */
388 #define a_float_modf A_FLOAT_F(modf)
389 #define a_float_frexp A_FLOAT_F(frexp)
390 #define a_float_ldexp A_FLOAT_F(ldexp)
391 #define a_float_scalbn A_FLOAT_F(scalbn)
392 #define a_float_scalbln A_FLOAT_F(scalbln)
393 #define a_float_nextafter A_FLOAT_F(nextafter)
394 #define a_float_nexttoward A_FLOAT_F(nexttoward)
395 #define a_float_copysign A_FLOAT_F(copysign)
397 #define a_float_ma A_FLOAT_F(fma)
398 #define a_float_nan A_FLOAT_F(nan)
399 #define a_float_abs A_FLOAT_F(fabs)
400 #define a_float_mod A_FLOAT_F(fmod)
401 #define a_float_max A_FLOAT_F(fmax)
402 #define a_float_min A_FLOAT_F(fmin)
403 #define a_float_dim A_FLOAT_F(fdim)
404 #define a_float_remquo A_FLOAT_F(remquo)
405 #define a_float_remainder A_FLOAT_F(remainder)
407 #define a_float_exp A_FLOAT_F(exp)
408 #define a_float_exp2 A_FLOAT_F(exp2)
409 #if defined(A_HAVE_EXPM1) && (A_HAVE_EXPM1 + 0 > 0)
410 #define a_float_expm1 A_FLOAT_F(expm1)
411 #endif /* A_HAVE_EXPM1 */
413 #define a_float_log A_FLOAT_F(log)
414 #define a_float_logb A_FLOAT_F(logb)
415 #define a_float_log2 A_FLOAT_F(log2)
416 #define a_float_log10 A_FLOAT_F(log10)
417 #if defined(A_HAVE_LOG1P) && (A_HAVE_LOG1P + 0 > 0)
418 #define a_float_log1p A_FLOAT_F(log1p)
419 #endif /* A_HAVE_LOG1P */
420 #define a_float_ilogb A_FLOAT_F(ilogb)
422 #define a_float_pow A_FLOAT_F(pow)
423 #define a_float_sqrt A_FLOAT_F(sqrt)
424 #define a_float_cbrt A_FLOAT_F(cbrt)
425 #if defined(A_HAVE_HYPOT) && (A_HAVE_HYPOT + 0 > 0)
426 #define a_float_hypot A_FLOAT_F(hypot)
427 #elif defined(_MSC_VER)
428 #define a_float_hypot A_FLOAT_F(_hypot)
429 #endif /* A_HAVE_HYPOT */
431 #define a_float_sin A_FLOAT_F(sin)
432 #define a_float_cos A_FLOAT_F(cos)
433 #define a_float_tan A_FLOAT_F(tan)
434 #define a_float_asin A_FLOAT_F(asin)
435 #define a_float_acos A_FLOAT_F(acos)
436 #define a_float_atan A_FLOAT_F(atan)
437 #if defined(A_HAVE_ATAN2) && (A_HAVE_ATAN2 + 0 > 0)
438 #define a_float_atan2 A_FLOAT_F(atan2)
439 #endif /* A_HAVE_ATAN2 */
441 #define a_float_sinh A_FLOAT_F(sinh)
442 #define a_float_cosh A_FLOAT_F(cosh)
443 #define a_float_tanh A_FLOAT_F(tanh)
444 #if defined(A_HAVE_ASINH) && (A_HAVE_ASINH + 0 > 0)
445 #define a_float_asinh A_FLOAT_F(asinh)
446 #endif /* A_HAVE_ASINH */
447 #if defined(A_HAVE_ACOSH) && (A_HAVE_ACOSH + 0 > 0)
448 #define a_float_acosh A_FLOAT_F(acosh)
449 #endif /* A_HAVE_ACOSH */
450 #if defined(A_HAVE_ATANH) && (A_HAVE_ATANH + 0 > 0)
451 #define a_float_atanh A_FLOAT_F(atanh)
452 #endif /* A_HAVE_ATANH */
454 #define a_float_erf A_FLOAT_F(erf)
455 #define a_float_erfc A_FLOAT_F(erfc)
456 #define a_float_tgamma A_FLOAT_F(tgamma)
457 #define a_float_lgamma A_FLOAT_F(lgamma)
459 #define a_float_ceil A_FLOAT_F(ceil)
460 #define a_float_floor A_FLOAT_F(floor)
461 #define a_float_trunc A_FLOAT_F(trunc)
462 #define a_float_round A_FLOAT_F(round)
463 #define a_float_lround A_FLOAT_F(lround)
464 #define a_float_llround A_FLOAT_F(llround)
465 #define a_float_nearbyint A_FLOAT_F(nearbyint)
466 #define a_float_rint A_FLOAT_F(rint)
467 #define a_float_lrintt A_FLOAT_F(lrint)
468 #define a_float_llrintt A_FLOAT_F(llrint)
472 #endif /* a/math.h */