FastLED 3.9.15
Loading...
Searching...
No Matches
math_macros.h
Go to the documentation of this file.
1#pragma once
2
4#include "fl/type_traits.h"
5
6namespace fl {
7
8// Fun fact, we can't define any function by the name of min,max,abs because
9// on some platforms these are macros. Therefore we can only use fl_min, fl_max, fl_abs.
10// This is needed for math macro ABS to work optimally.
11template <typename T> inline T fl_abs(T value) {
12 return value < 0 ? -value : value;
13}
14
16FL_DISABLE_WARNING(sign-compare)
21
22
23// Template functions for MIN and MAX to avoid statement repetition
24// Returns the most promotable type between the two arguments
25template <typename T, typename U> inline common_type_t<T, U> fl_min(T a, U b) {
26 return (a < b) ? a : b;
27}
28
29template <typename T, typename U> inline common_type_t<T, U> fl_max(T a, U b) {
30 return (a > b) ? a : b;
31}
32
34} // namespace fl
35
36#ifndef MAX
37#define MAX(a, b) fl::fl_max(a, b)
38#endif
39
40#ifndef MIN
41#define MIN(a, b) fl::fl_min(a, b)
42#endif
43
44#ifndef ABS
45#define ABS(x) fl::fl_abs(x)
46#endif
47
48#ifndef EPSILON_F
49// smallest possible float
50#define EPSILON_F 1.19209290e-07F
51#endif
52
53#ifndef EPSILON_D
54// smallest possible double
55#define EPSILON_D 2.2204460492503131e-16
56#endif
57
58#ifndef ALMOST_EQUAL
59#define ALMOST_EQUAL(a, b, small) (ABS((a) - (b)) < small)
60#endif
61
62#ifndef ALMOST_EQUAL_FLOAT
63#define ALMOST_EQUAL_FLOAT(a, b) (ABS((a) - (b)) < EPSILON_F)
64#endif
65
66
67
68#ifndef ALMOST_EQUAL_DOUBLE
69#define ALMOST_EQUAL_EPSILON(a, b, epsilon) (ABS((a) - (b)) < (epsilon))
70#endif
71
72#ifndef ALMOST_EQUAL_DOUBLE
73#define ALMOST_EQUAL_DOUBLE(a, b) ALMOST_EQUAL_EPSILON(a, b, EPSILON_F)
74#endif
75
76#ifndef INFINITY_DOUBLE
77#define INFINITY_DOUBLE (1.0 / 0.0)
78#endif
79
80#ifndef INFINITY_FLOAT
81#define INFINITY_FLOAT (1.0f / 0.0f)
82#endif
83
84#ifndef FLT_MAX
85#define FLT_MAX 3.402823466e+38F
86#endif
87
88#ifndef PI
89#define PI 3.1415926535897932384626433832795
90#endif
91
92#ifndef M_PI
93#define M_PI PI
94#endif
#define FL_DISABLE_WARNING(warning)
#define FL_DISABLE_WARNING_IMPLICIT_INT_CONVERSION
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_SIGN_CONVERSION
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_FLOAT_CONVERSION
typename common_type< T, U >::type common_type_t
T fl_abs(T value)
Definition math_macros.h:11
FL_DISABLE_WARNING_PUSH U common_type_t< T, U > fl_min(T a, U b)
Definition math_macros.h:25
common_type_t< T, U > fl_max(T a, U b)
Definition math_macros.h:29
IMPORTANT!
Definition crgb.h:20