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;
86template <
typename T,
typename L,
typename H>
89 if (
value < lo)
return lo;
90 if (
value > hi)
return hi;
97template <
typename T,
typename U>
99 return fl::abs(a - b) < tolerance;
113#define FL_MAX(a, b) fl::max(a, b)
117#define FL_MIN(a, b) fl::min(a, b)
121#define FL_ABS(x) fl::abs(x)
124#ifndef FL_ALMOST_EQUAL
125#define FL_ALMOST_EQUAL(a, b, small) fl::almost_equal(a, b, small)
128#ifndef FL_ALMOST_EQUAL_FLOAT
129#define FL_ALMOST_EQUAL_FLOAT(a, b) fl::almost_equal(static_cast<float>(a), static_cast<float>(b))
132#ifndef FL_ALMOST_EQUAL_EPSILON
133#define FL_ALMOST_EQUAL_EPSILON(a, b, epsilon) fl::almost_equal(a, b, epsilon)
136#ifndef FL_ALMOST_EQUAL_DOUBLE
137#define FL_ALMOST_EQUAL_DOUBLE(a, b) fl::almost_equal(static_cast<double>(a), static_cast<double>(b))
153template <
typename T,
typename U>
struct map_range_math {
155 if (in_min == in_max)
158 (
value - in_min) * (out_max - out_min) / (in_max - in_min);
163template <>
struct map_range_math<
u8,
u8> {
169template <>
struct map_range_math<u16, u16> {
170 static u16
map(u16
value, u16 in_min, u16 in_max,
175template <
typename T>
bool equals(T a, T b)
FL_NO_EXCEPT {
return a == b; }
181template <
typename T,
typename U>
184 if (map_range_detail::equals(
value, in_min)) {
187 if (map_range_detail::equals(
value, in_max)) {
190 return map_range_detail::map_range_math<T, U>::map(
value, in_min, in_max, out_min, out_max);
193template <
typename T,
typename U>
200namespace map_range_detail {
202inline u8 map_range_math<u8, u8>::map(
u8 value,
u8 in_min,
u8 in_max,
204 if (
value == in_min) {
207 if (
value == in_max) {
211 i16 in_min16 = in_min;
212 i16 in_max16 = in_max;
213 i16 out_min16 = out_min;
214 i16 out_max16 = out_max;
216 out_min16, out_max16);
219 }
else if (out16 > 255) {
222 return static_cast<u8>(out16);
225inline u16 map_range_math<u16, u16>::map(u16
value, u16 in_min, u16 in_max,
227 if (
value == in_min) {
230 if (
value == in_max) {
234 u32 in_min32 = in_min;
235 u32 in_max32 = in_max;
236 u32 out_min32 = out_min;
237 u32 out_max32 = out_max;
239 out_min32, out_max32);
243 return static_cast<u16
>(out32);
296 return static_cast<int>((
value >
static_cast<float>(
static_cast<int>(
value)))
297 ?
static_cast<int>(
value) + 1
298 :
static_cast<int>(
value));
314template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
320template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
326inline typename enable_if<!is_integral<T>::value, T>::type
334template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
340template<
typename T>
inline typename enable_if<is_integral<T>::value,
long>::type
346inline typename enable_if<!is_integral<T>::value, T>::type
348 return static_cast<T
>(
fmod_impl_float(
static_cast<float>(
x),
static_cast<float>(
y)));
354template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
362template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
368template<
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
382template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
388template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
394template<
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
408template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
415 union {
float f; u32 i; } u;
417 i32 e =
static_cast<i32
>(u.i >> 23) - 127;
418 u.i = (u.i & 0x007FFFFFu) | 0x3F800000u;
421 float log2m =
t * (1.3327635f +
t * (-0.3327635f));
422 return (
static_cast<float>(e) + log2m) * 0.6931471805599453f;
428template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
434template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
440template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
446template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
453template<
typename T,
typename =
void>
464template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
470inline typename enable_if<sqrt_detail::has_static_sqrt<T>::value,
decltype(T::sqrt(
declval<T>()))>::type
472 return T::sqrt(
value);
477template<
typename T,
typename =
void>
488 return T::floor(
value);
493template<
typename T,
typename =
void>
504 return T::ceil(
value);
510template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
518template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
524template<
typename T>
inline typename enable_if<is_integral<T>::value,
float>::type
531 return deg *
static_cast<T
>(0.017453292519943295);
536 return rad *
static_cast<T
>(57.29577951308232);
543inline typename enable_if<is_floating_point<T>::value>::type
545 out_sin =
static_cast<T
>(
fl::sinf(
static_cast<float>(angle)));
546 out_cos =
static_cast<T
>(
fl::cosf(
static_cast<float>(angle)));
551inline typename enable_if<is_integral<T>::value>::type
553 out_sin =
fl::sinf(
static_cast<float>(angle));
554 out_cos =
fl::cosf(
static_cast<float>(angle));
bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2) FL_NO_EXCEPT
float logf(float value) FL_NO_EXCEPT
float acosf(float value) FL_NO_EXCEPT
double ceil_impl_double(double value) FL_NO_EXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, T >::type sin(T angle) FL_NO_EXCEPT
double fabs_impl_double(double value) FL_NO_EXCEPT
typename common_type< T, U >::type common_type_t
u8 u8 fract8 blur_amount FL_NO_EXCEPT
constexpr int type_rank< T >::value
long lround_impl_float(float value) FL_NO_EXCEPT
double ldexp_impl_double(double value, int exp) FL_NO_EXCEPT
constexpr bool almost_equal(T a, T b, U tolerance) FL_NO_EXCEPT
double tan_impl_double(double value) FL_NO_EXCEPT
double sin_impl_double(double value) FL_NO_EXCEPT
double hypot(double x, double y) FL_NO_EXCEPT
float hypotf(float x, float y) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, T >::type cos(T angle) FL_NO_EXCEPT
MapRedBlackTree< Key, T, Compare, fl::allocator_slab< char > > map
float log2f(float value) FL_NO_EXCEPT
float asinf(float value) FL_NO_EXCEPT
add_rvalue_reference< T >::type declval() FL_NO_EXCEPT
enable_if<!is_integral< T >::value, T >::type fmod(T x, T y) FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
float sqrt_impl_float(float value) FL_NO_EXCEPT
float tanf(float value) FL_NO_EXCEPT
float sinf(float value) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NO_EXCEPT
float fast_logf_approx(float x) FL_NO_EXCEPT
double fmod_impl_double(double x, double y) FL_NO_EXCEPT
float atan2f(float y, float x) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, T >::type atan2(T y, T x) FL_NO_EXCEPT
float exp_impl_float(float value) FL_NO_EXCEPT
double ldexp(double value, int exp) FL_NO_EXCEPT
integral_constant< bool, false > false_type
float floor_impl_float(float value) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type ceil(T x) FL_NO_EXCEPT
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, T >::type acos(T x) FL_NO_EXCEPT
double sqrt_impl_double(double value) FL_NO_EXCEPT
double floor_impl_double(double value) FL_NO_EXCEPT
long lround(double value) FL_NO_EXCEPT
double pow_impl_double(double base, double exponent) FL_NO_EXCEPT
float atanf(float value) FL_NO_EXCEPT
double acos_impl_double(double value) FL_NO_EXCEPT
long lround_impl_double(double value) FL_NO_EXCEPT
float atan_impl_float(float value) FL_NO_EXCEPT
FASTLED_FORCE_INLINE U map_range_clamped(T value, T in_min, T in_max, U out_min, U out_max) FL_NO_EXCEPT
float sin_impl_float(float value) FL_NO_EXCEPT
float log10f(float value) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, T >::type atan(T x) FL_NO_EXCEPT
float acos_impl_float(float value) FL_NO_EXCEPT
float pow_impl_float(float base, float exponent) FL_NO_EXCEPT
float hypot_impl_float(float x, float y) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, void >::type sincos(T angle, T &out_sin, T &out_cos) FL_NO_EXCEPT
float ceil_impl_float(float value) FL_NO_EXCEPT
double asin_impl_double(double value) FL_NO_EXCEPT
constexpr int ceil_constexpr(float value) FL_NO_EXCEPT
double atan_impl_double(double value) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, T >::type pow(T base, T exp) FL_NO_EXCEPT
double cos_impl_double(double value) FL_NO_EXCEPT
double log(double value) FL_NO_EXCEPT
float sqrtf(float value) FL_NO_EXCEPT
double log10(double value) FL_NO_EXCEPT
float round_impl_float(float value) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, T >::type asin(T x) FL_NO_EXCEPT
double round< double >(double value) FL_NO_EXCEPT
double tan(double value) FL_NO_EXCEPT
double fabs(double value) FL_NO_EXCEPT
float log_impl_float(float value) FL_NO_EXCEPT
float fmodf(float x, float y) FL_NO_EXCEPT
double log2(double value) FL_NO_EXCEPT
float cosf(float value) FL_NO_EXCEPT
double fmod< double >(double x, double y) FL_NO_EXCEPT
float fabsf(float value) FL_NO_EXCEPT
float roundf(float value) FL_NO_EXCEPT
float powf(float base, float exponent) FL_NO_EXCEPT
float log10_impl_float(float value) FL_NO_EXCEPT
float floorf(float value) FL_NO_EXCEPT
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NO_EXCEPT
double round_impl_double(double value) FL_NO_EXCEPT
double log_impl_double(double value) FL_NO_EXCEPT
constexpr T degrees(T rad) FL_NO_EXCEPT
float ldexp_impl_float(float value, int exp) FL_NO_EXCEPT
float ceilf(float value) FL_NO_EXCEPT
double atan2_impl_double(double y, double x) FL_NO_EXCEPT
double hypot_impl_double(double x, double y) FL_NO_EXCEPT
long lroundf(float value) FL_NO_EXCEPT
float tan_impl_float(float value) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, int >::type sign(T x) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NO_EXCEPT
float asin_impl_float(float value) FL_NO_EXCEPT
integral_constant< bool, true > true_type
float expf(float value) FL_NO_EXCEPT
double exp_impl_double(double value) FL_NO_EXCEPT
constexpr T radians(T deg) FL_NO_EXCEPT
double log10_impl_double(double value) FL_NO_EXCEPT
float fabs_impl_float(float value) FL_NO_EXCEPT
float cos_impl_float(float value) FL_NO_EXCEPT
float atan2_impl_float(float y, float x) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type floor(T x) FL_NO_EXCEPT
float ldexpf(float value, int exp) FL_NO_EXCEPT
float fmod_impl_float(float x, float y) FL_NO_EXCEPT
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