12#if __has_include("arm_math.h")
26 #pragma message("CMSIS-DSP is used.")
30 #pragma message("CMSIS-DSP is NOT used. cmath is used instead.")
39template <std::
floating_po
int FloatType>
40inline constexpr FloatType
pi = std::numbers::pi_v<FloatType>;
42template <std::
floating_po
int FloatType>
43inline constexpr FloatType
twoPi = 2.0 * std::numbers::pi_v<FloatType>;
45template <std::
floating_po
int FloatType>
46inline constexpr FloatType
halfPi = std::numbers::pi_v<FloatType> / 2.0;
48template <std::
floating_po
int FloatType>
49inline constexpr FloatType
sqrt2 = std::numbers::sqrt2_v<FloatType>;
51template <std::
floating_po
int FloatType>
52inline constexpr FloatType
invSqrt2 = 1.0 / std::numbers::sqrt2_v<FloatType>;
61constexpr inline float sin (
float x)
63 if (std::is_constant_evaluated())
66 auto fabs = [] (
float v) ->
float
67 {
return (v < 0.0f) ? (-v) : (v); };
77 tmp *= xSq / (fact * (fact + 1.0f));
80 }
while (fabs (tmp) >= std::numeric_limits<float>::epsilon());
88 return arm_sin_f32 (x);
101constexpr inline double sin (
double x)
103 if (std::is_constant_evaluated())
106 auto fabs = [] (
double v) ->
double
107 {
return (v < 0.0) ? (-v) : (v); };
109 double xSq = -(x * x);
117 tmp *= xSq / (fact * (fact + 1.0));
120 }
while (fabs (tmp) >= std::numeric_limits<double>::epsilon());
138constexpr inline float cos (
float x)
140 if (std::is_constant_evaluated())
143 auto fabs = [] (
float v) ->
float
144 {
return (v <
float (0.0)) ? (-v) : (v); };
145 float xSq = -(x * x);
146 float series = float (1.0);
147 float tmp = float (1.0);
148 float fact = float (1.0);
153 tmp *= xSq / (fact * (fact + float (1.0)));
156 }
while (fabs (tmp) >= std::numeric_limits<float>::epsilon());
164 return arm_cos_f32 (x);
171constexpr inline double cos (
double x)
173 if (std::is_constant_evaluated())
176 auto fabs = [] (
double v) ->
double
177 {
return (v < 0.0) ? (-v) : (v); };
178 double xSq = -(x * x);
186 tmp *= xSq / (fact * (fact + 1.0));
189 }
while (fabs (tmp) >= std::numeric_limits<double>::epsilon());
constexpr FloatType twoPi
2π
Definition: ame_Math.hpp:43
constexpr FloatType pi
π
Definition: ame_Math.hpp:40
constexpr FloatType invSqrt2
1/sqrt2
Definition: ame_Math.hpp:52
constexpr FloatType sqrt2
sqrt2
Definition: ame_Math.hpp:49
constexpr float cos(float x)
cosf.
Definition: ame_Math.hpp:138
constexpr FloatType halfPi
π/2
Definition: ame_Math.hpp:46
constexpr float sin(float x)
sin for float
Definition: ame_Math.hpp:61