26#define FL_PI 3.1415926535897932384626433832795
30#define FL_E 2.71828182845904523536
38#define FL_EPSILON_F 1.19209290e-07F
42#define FL_EPSILON_D 2.2204460492503131e-16
45#ifndef FL_INFINITY_FLOAT
46#define FL_INFINITY_FLOAT (1.0f / 0.0f)
49#ifndef FL_INFINITY_DOUBLE
50#define FL_INFINITY_DOUBLE (1.0 / 0.0)
54#define FL_FLT_MAX 3.402823466e+38F
72 return (a < b) ? a : b;
76 return (a > b) ? a : b;
82 if (
value < lo)
return lo;
83 if (
value > hi)
return hi;
89template <
typename T,
typename U>
91 return fl::abs(a - b) < tolerance;
105#define FL_MAX(a, b) fl::max(a, b)
109#define FL_MIN(a, b) fl::min(a, b)
113#define FL_ABS(x) fl::abs(x)
116#ifndef FL_ALMOST_EQUAL
117#define FL_ALMOST_EQUAL(a, b, small) fl::almost_equal(a, b, small)
120#ifndef FL_ALMOST_EQUAL_FLOAT
121#define FL_ALMOST_EQUAL_FLOAT(a, b) fl::almost_equal(static_cast<float>(a), static_cast<float>(b))
124#ifndef FL_ALMOST_EQUAL_EPSILON
125#define FL_ALMOST_EQUAL_EPSILON(a, b, epsilon) fl::almost_equal(a, b, epsilon)
128#ifndef FL_ALMOST_EQUAL_DOUBLE
129#define FL_ALMOST_EQUAL_DOUBLE(a, b) fl::almost_equal(static_cast<double>(a), static_cast<double>(b))
145template <
typename T,
typename U>
struct map_range_math {
147 if (in_min == in_max)
150 (
value - in_min) * (out_max - out_min) / (in_max - in_min);
155template <>
struct map_range_math<
u8,
u8> {
161template <>
struct map_range_math<u16, u16> {
162 static u16
map(u16
value, u16 in_min, u16 in_max,
167template <
typename T>
bool equals(T a, T b)
FL_NOEXCEPT {
return a == b; }
173template <
typename T,
typename U>
176 if (map_range_detail::equals(
value, in_min)) {
179 if (map_range_detail::equals(
value, in_max)) {
182 return map_range_detail::map_range_math<T, U>::map(
value, in_min, in_max, out_min, out_max);
185template <
typename T,
typename U>
192namespace map_range_detail {
194inline u8 map_range_math<u8, u8>::map(
u8 value,
u8 in_min,
u8 in_max,
196 if (
value == in_min) {
199 if (
value == in_max) {
203 i16 in_min16 = in_min;
204 i16 in_max16 = in_max;
205 i16 out_min16 = out_min;
206 i16 out_max16 = out_max;
208 out_min16, out_max16);
211 }
else if (out16 > 255) {
214 return static_cast<u8>(out16);
217inline u16 map_range_math<u16, u16>::map(u16
value, u16 in_min, u16 in_max,
219 if (
value == in_min) {
222 if (
value == in_max) {
226 u32 in_min32 = in_min;
227 u32 in_max32 = in_max;
228 u32 out_min32 = out_min;
229 u32 out_max32 = out_max;
231 out_min32, out_max32);
235 return static_cast<u16
>(out32);
288 return static_cast<int>((
value >
static_cast<float>(
static_cast<int>(
value)))
289 ?
static_cast<int>(
value) + 1
290 :
static_cast<int>(
value));
306template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
312template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
318inline typename enable_if<!is_integral<T>::value, T>::type
326template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
332template<
typename T>
inline typename enable_if<is_integral<T>::value,
long>::type
338inline typename enable_if<!is_integral<T>::value, T>::type
340 return static_cast<T
>(
fmod_impl_float(
static_cast<float>(
x),
static_cast<float>(
y)));
346template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
354template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
360template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
366template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
374template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
380template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
386template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
392template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
400template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
407 union {
float f; u32 i; } u;
409 i32 e =
static_cast<i32
>(u.i >> 23) - 127;
410 u.i = (u.i & 0x007FFFFFu) | 0x3F800000u;
413 float log2m =
t * (1.3327635f +
t * (-0.3327635f));
414 return (
static_cast<float>(e) + log2m) * 0.6931471805599453f;
420template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
426template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
432template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
438template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
445template<
typename T,
typename =
void>
456template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
462inline typename enable_if<sqrt_detail::has_static_sqrt<T>::value,
decltype(T::sqrt(
declval<T>()))>::type
464 return T::sqrt(
value);
469template<
typename T,
typename =
void>
480 return T::floor(
value);
485template<
typename T,
typename =
void>
496 return T::ceil(
value);
502template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
510template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
516template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
523 return deg *
static_cast<T
>(0.017453292519943295);
528 return rad *
static_cast<T
>(57.29577951308232);
535inline typename enable_if<is_floating_point<T>::value>::type
537 out_sin =
static_cast<T
>(
fl::sinf(
static_cast<float>(angle)));
538 out_cos =
static_cast<T
>(
fl::cosf(
static_cast<float>(angle)));
543inline typename enable_if<is_integral<T>::value>::type
545 out_sin =
fl::sinf(
static_cast<float>(angle));
546 out_cos =
fl::cosf(
static_cast<float>(angle));
double hypot_impl_double(double x, double y)
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
long lround(double value) FL_NOEXCEPT
constexpr int ceil_constexpr(float value) FL_NOEXCEPT
double atan2_impl_double(double y, double x)
float log_impl_float(float value)
float fabs_impl_float(float value)
float sqrtf(float value) FL_NOEXCEPT
typename common_type< T, U >::type common_type_t
double hypot(double x, double y) FL_NOEXCEPT
double fabs(double value) FL_NOEXCEPT
constexpr int type_rank< T >::value
double sqrt_impl_double(double value)
enable_if< is_fixed_point< T >::value, T >::type atan2(T y, T x) FL_NOEXCEPT
double ldexp(double value, int exp) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
float roundf(float value) FL_NOEXCEPT
float powf(float base, float exponent) FL_NOEXCEPT
double atan_impl_double(double value)
double cos_impl_double(double value)
float expf(float value) FL_NOEXCEPT
MapRedBlackTree< Key, T, Compare, fl::allocator_slab< char > > map
float floorf(float value) FL_NOEXCEPT
float exp_impl_float(float value)
constexpr enable_if< is_fixed_point< T >::value, T >::type ceil(T x) FL_NOEXCEPT
double pow_impl_double(double base, double exponent)
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max) FL_NOEXCEPT
add_rvalue_reference< T >::type declval() FL_NOEXCEPT
float ceil_impl_float(float value)
enable_if< is_fixed_point< T >::value, void >::type sincos(T angle, T &out_sin, T &out_cos) FL_NOEXCEPT
double tan_impl_double(double value)
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NOEXCEPT
double sin_impl_double(double value)
double acos_impl_double(double value)
integral_constant< bool, false > false_type
double log2(double value) FL_NOEXCEPT
float fmod_impl_float(float x, float y)
float log10_impl_float(float value)
double ldexp_impl_double(double value, int exp)
float atan2_impl_float(float y, float x)
constexpr enable_if< is_fixed_point< T >::value, T >::type floor(T x) FL_NOEXCEPT
float sinf(float value) FL_NOEXCEPT
double fabs_impl_double(double value)
constexpr bool almost_equal(T a, T b, U tolerance) FL_NOEXCEPT
float log10f(float value) FL_NOEXCEPT
bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, int >::type sign(T x) FL_NOEXCEPT
double log(double value) FL_NOEXCEPT
double log_impl_double(double value)
double floor_impl_double(double value)
float ceilf(float value) FL_NOEXCEPT
long lroundf(float value) FL_NOEXCEPT
float acos_impl_float(float value)
enable_if< is_fixed_point< T >::value, T >::type acos(T x) FL_NOEXCEPT
float fast_logf_approx(float x) FL_NOEXCEPT
double log10_impl_double(double value)
float round_impl_float(float value)
double round< double >(double value) FL_NOEXCEPT
constexpr T radians(T deg) FL_NOEXCEPT
float asinf(float value) FL_NOEXCEPT
float fmodf(float x, float y) FL_NOEXCEPT
float cos_impl_float(float value)
float fabsf(float value) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type pow(T base, T exp) FL_NOEXCEPT
double round_impl_double(double value)
float pow_impl_float(float base, float exponent)
float atanf(float value) FL_NOEXCEPT
long lround_impl_float(float value)
float ldexpf(float value, int exp) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type cos(T angle) FL_NOEXCEPT
float hypot_impl_float(float x, float y)
double tan(double value) FL_NOEXCEPT
enable_if<!is_integral< T >::value, T >::type fmod(T x, T y) FL_NOEXCEPT
float tanf(float value) FL_NOEXCEPT
float sqrt_impl_float(float value)
double ceil_impl_double(double value)
float tan_impl_float(float value)
double fmod< double >(double x, double y) FL_NOEXCEPT
double fmod_impl_double(double x, double y)
FASTLED_FORCE_INLINE U map_range_clamped(T value, T in_min, T in_max, U out_min, U out_max) FL_NOEXCEPT
float atan_impl_float(float value)
float sin_impl_float(float value)
float hypotf(float x, float y) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type sin(T angle) FL_NOEXCEPT
double log10(double value) FL_NOEXCEPT
float floor_impl_float(float value)
float acosf(float value) FL_NOEXCEPT
long lround_impl_double(double value)
float log2f(float value) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type asin(T x) FL_NOEXCEPT
float asin_impl_float(float value)
float cosf(float value) FL_NOEXCEPT
float atan2f(float y, float x) FL_NOEXCEPT
double asin_impl_double(double value)
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NOEXCEPT
integral_constant< bool, true > true_type
double exp_impl_double(double value)
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NOEXCEPT
float logf(float value) FL_NOEXCEPT
constexpr T degrees(T rad) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type atan(T x) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT
float ldexp_impl_float(float value, int exp)
Base definition for an LED controller.
#define FL_DISABLE_WARNING(warning)
#define FL_DISABLE_WARNING_IMPLICIT_INT_CONVERSION
#define FASTLED_FORCE_INLINE
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_SIGN_CONVERSION
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_FLOAT_CONVERSION