RTduino Source Code Reference Manual
Macros | Functions
Maths

Mathematical definitions and functions. More...

Macros

#define PI   3.1415926535897932384626433832795
 A constant representing the ratio of a circle's circumference to its diameter.
 
#define HALF_PI   1.5707963267948966192313216916398
 A constant representing half of the mathematical constant π (pi) in programming and mathematics.
 
#define TWO_PI   6.283185307179586476925286766559
 A constant representing two times the mathematical constant π (pi) in programming and mathematics.
 
#define DEG_TO_RAD   0.017453292519943295769236907684886
 A constant for converting degrees to radians in mathematics and programming applications.
 
#define RAD_TO_DEG   57.295779513082320876798154814105
 A constant for converting radians to degrees in mathematical and programming contexts.
 
#define EULER   2.718281828459045235360287471352
 Euler's constant.
 
#define min(a, b)   ((a)<(b)?(a):(b))
 Returns the smaller of two values. More...
 
#define max(a, b)   ((a)>(b)?(a):(b))
 Returns the larger of two values. More...
 
#define constrain(amt, low, high)   ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
 Constrains a value to be within a specified range. More...
 
#define radians(deg)   ((deg)*DEG_TO_RAD)
 Converts degrees to radians. More...
 
#define degrees(rad)   ((rad)*RAD_TO_DEG)
 Converts radians to degrees. More...
 
#define sq(x)   ((x)*(x)) /* x^2 */
 Squares a number. More...
 

Functions

long map (long x, long in_min, long in_max, long out_min, long out_max)
 Maps a value from one range to another. More...
 

Detailed Description

Mathematical definitions and functions.

Macro Definition Documentation

◆ constrain

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

Constrains a value to be within a specified range.

Parameters
amtThe value to constrain.
lowThe lower end of the range.
highThe upper end of the range.
Returns
The constrained value.

◆ degrees

#define degrees (   rad)    ((rad)*RAD_TO_DEG)

Converts radians to degrees.

Parameters
radThe angle in radians.
Returns
The angle in degrees.

◆ max

#define max (   a,
 
)    ((a)>(b)?(a):(b))

Returns the larger of two values.

Parameters
aFirst value.
bSecond value.
Returns
The larger of the two values.

◆ min

#define min (   a,
 
)    ((a)<(b)?(a):(b))

Returns the smaller of two values.

Parameters
aFirst value.
bSecond value.
Returns
The smaller of the two values.

◆ radians

#define radians (   deg)    ((deg)*DEG_TO_RAD)

Converts degrees to radians.

Parameters
degThe angle in degrees.
Returns
The angle in radians.

◆ sq

#define sq (   x)    ((x)*(x)) /* x^2 */

Squares a number.

Parameters
xThe number to square.
Returns
The squared value.

Function Documentation

◆ map()

long map ( long  x,
long  in_min,
long  in_max,
long  out_min,
long  out_max 
)

Maps a value from one range to another.

Parameters
xThe value to map.
in_minThe lower bound of the input range.
in_maxThe upper bound of the input range.
out_minThe lower bound of the output range.
out_maxThe upper bound of the output range.
Returns
The mapped value.
See also
https://www.arduino.cc/reference/en/language/functions/math/map