Loading...
Searching...
No Matches
Math

min(), max(), constrain(), map(), sq() and angle conversions. More...

Macros

#define constrain(amt, low, high)
 Limits a value to a range: low if below it, high if above it.
#define sq(x)
 The square of a number, x * x.
#define radians(deg)
 Converts degrees to radians.
#define degrees(rad)
 Converts radians to degrees.
#define PI   3.1415926535897932384626433832795
 π, 3.14159...
#define HALF_PI   1.5707963267948966192313216916398
 π / 2.
#define TWO_PI   6.283185307179586476925286766559
 2π.
#define DEG_TO_RAD   0.017453292519943295769236907684886
 Radians per degree, π / 180.
#define RAD_TO_DEG   57.295779513082320876798154814105
 Degrees per radian, 180 / π.
#define EULER   2.718281828459045235360287471352
 e, 2.71828...

Functions

template<class T, class L>
auto min (const T &a, const L &b) -> decltype((b< a) ? b :a)
 The smaller of two values.
template<class T, class L>
auto max (const T &a, const L &b) -> decltype((b< a) ? b :a)
 The larger of two values.
long map (long, long, long, long, long)
 Re-maps a number from one range to another, e.g. 0-1023 to 0-255.

Detailed Description

min(), max(), constrain(), map(), sq() and angle conversions.

Macro Definition Documentation

◆ constrain

#define constrain ( amt,
low,
high )
Value:
((amt)<(low)?(low):((amt)>(high)?(high):(amt)))

Limits a value to a range: low if below it, high if above it.

Note
A macro: do not put x++ or a function call in the arguments.

◆ degrees

#define degrees ( rad)
Value:
((rad)*RAD_TO_DEG)
#define RAD_TO_DEG
Degrees per radian, 180 / π.
Definition Common.h:55

Converts radians to degrees.

◆ radians

#define radians ( deg)
Value:
((deg)*DEG_TO_RAD)
#define DEG_TO_RAD
Radians per degree, π / 180.
Definition Common.h:54

Converts degrees to radians.

◆ sq

#define sq ( x)
Value:
((x)*(x))

The square of a number, x * x.

Note
A macro: do not put x++ or a function call in the argument.

Function Documentation

◆ map()

long map ( long ,
long ,
long ,
long ,
long  )

Re-maps a number from one range to another, e.g. 0-1023 to 0-255.

map(x, in_min, in_max, out_min, out_max). Integer maths: the result is rounded down and not limited to the output range (use constrain()).

Returns
The value in the output range.

◆ max()

template<class T, class L>
auto max ( const T & a,
const L & b ) -> decltype((b< a) ? b :a)

The larger of two values.

Template Parameters
TType of a.
LType of b.
Parameters
aFirst value.
bSecond value.
Returns
b if a is less than it, otherwise a.

◆ min()

template<class T, class L>
auto min ( const T & a,
const L & b ) -> decltype((b< a) ? b :a)

The smaller of two values.

Template Parameters
TType of a.
LType of b.
Parameters
aFirst value.
bSecond value.
Returns
b if it is less than a, otherwise a.