libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_numeric.h
Go to the documentation of this file.
1/*! \file
2 * \brief General numeric constants and computations
3 * \ingroup numeric
4 *
5 * \author Shirobon
6 * \author Falco Girgis
7 */
8
9#ifndef GIMBAL_NUMERIC_H
10#define GIMBAL_NUMERIC_H
11
12#include "../core/gimbal_decls.h"
13#include "../preprocessor/gimbal_macro_utils.h"
14#include <float.h>
15#include <math.h>
16
17#ifndef M_PI
18# define M_PI (3.14159265358979323846264338327950288)
19#endif
20
21#ifndef M_E
22# define M_E (2.71828182845904523536)
23#endif
24
25#define gblPow2Next(X) GBL_META_GENERIC_MACRO_GENERATE(GBL_POW2_NEXT_TRAITS_, X)(X)
26
28
29/*! \defgroup numeric Numeric
30 * \ingroup algorithms
31 * \brief Collection of assorted numeric algorithms.
32 * @{
33 */
34GBL_EXPORT uint8_t gblPow2Next_u8 (uint8_t n) GBL_NOEXCEPT;
35GBL_EXPORT uint16_t gblPow2Next_u16 (uint16_t n) GBL_NOEXCEPT;
36GBL_EXPORT uint32_t gblPow2Next_u32 (uint32_t n) GBL_NOEXCEPT;
37GBL_EXPORT uint64_t gblPow2Next_u64 (uint64_t n) GBL_NOEXCEPT;
38GBL_EXPORT GblBool gblPow2Check (size_t n) GBL_NOEXCEPT;
39GBL_EXPORT int gblFibonacci (int n) GBL_NOEXCEPT;
40GBL_EXPORT int gblGcd (int u, int v) GBL_NOEXCEPT;
41GBL_EXPORT int gblLcm (int u, int v) GBL_NOEXCEPT;
42GBL_EXPORT uint32_t gblNtohl (uint32_t n) GBL_NOEXCEPT;
43GBL_EXPORT uint32_t gblHtonl (uint32_t x) GBL_NOEXCEPT;
44GBL_EXPORT int gblParity (uint8_t n) GBL_NOEXCEPT;
45GBL_EXPORT size_t gblAlignedAllocSizeDefault (size_t bytes) GBL_NOEXCEPT;
46GBL_EXPORT size_t gblAlignedAllocSize (size_t size, size_t align/*=0*/) GBL_NOEXCEPT;
47GBL_EXPORT uint32_t gblPrimeNextDouble (uint32_t number) GBL_NOEXCEPT;
48GBL_EXPORT GblBool gblPrimeCheck (int n) GBL_NOEXCEPT;
49GBL_EXPORT unsigned long gblBinomialCoeff (unsigned n, unsigned k) GBL_NOEXCEPT;
50GBL_EXPORT unsigned long gblCatalan (unsigned n) GBL_NOEXCEPT;
51//! \todo rename me gblEqualsf
53 double b,
54 double e/*=DBL_EPSILON*/) GBL_NOEXCEPT;
55GBL_EXPORT float gblDegToRadf (float degrees) GBL_NOEXCEPT;
56GBL_EXPORT float gblRadToDegf (float radians) GBL_NOEXCEPT;
57
58#if 0
59GBL_EXPORT void gblCartesianToPolarf (float x, float y, float* pRad, float* pAng) GBL_NOEXCEPT;
60GBL_EXPORT void gblPolarToCartesianf (float rad, float ang, float* pX, float* pY) GBL_NOEXCEPT;
61GBL_EXPORT float gblLerpf (float v1, float v2, float frac) GBL_NOEXCEPT;
62// various interpolation functions
63GBL_EXPORT float gblDynamicWeightedMovingAverage(float current, float prev, float maxDist, float minWeight, float maxWeight) GBL_NOEXCEPT;
64GBL_EXPORT float gblRangePctf(float min, float max, float value) GBL_NOEXCEPT;
65GBL_EXPORT GblBool gblPow2Checkz(size_t value) GBL_NOEXCEPT;
66GBL_EXPORT GblBool gblWithinCheckf(float value, float min, float max) GBL_NOEXCEPT;
67GBL_EXPORT GblBool gblWithinInclusiveCheckf(float value, float min, float max) GBL_NOEXCEPT;
68//GBL_EXPORT float gblPulsatef(float inTime, float inPulsesPerSecond, float inPhase) GBL_NOEXCEPT;
69//GBL_EXPORT float gblPerlinNoise(float value) GBL_NOEXCEPT;
70//GBL_EXPORT float gblWrapf(float value) GBL_NOEXCEPT;
71#endif
72
73/// @}
74
76
77///\cond
78#define gblAlignedAllocSize(...)
79 gblAlignedAllocSizeDefault_(__VA_ARGS__)
80#define gblAlignedAllocSizeDefault_(...)
81 gblAlignedAllocSizeDefault__(__VA_ARGS__, 0)
82#define gblAlignedAllocSizeDefault__(size, align, ...)
83 (gblAlignedAllocSize)(size, align)
84
85#define GBL_POW2_NEXT_TRAITS_ (
86 gblPow2Next_u64,
87 (
88 (uint8_t, gblPow2Next_u8),
89 (uint16_t, gblPow2Next_u16),
90 (uint32_t, gblPow2Next_u32),
91 (uint64_t, gblPow2Next_u64)
92 )
93 )
94
95#define gblFloatEquals(...)
96 gblFloatEqualsDefault_(__VA_ARGS__, DBL_EPSILON)
97#define gblFloatEqualsDefault_(a, b, e, ...)
98 (gblFloatEquals)(a, b, e)
99///\endcond
100
101#endif // GIMBAL_NUMERIC_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_META_GENERIC_MACRO_GENERATE(traits, X)
#define M_E
#define M_PI
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
GblBool gblFloatEquals(double a, double b, double e)