ContentsIndex
PreviousUpNext
Math
Functions | Macros

 

The Math API provides four sets of maths functions: 

  • Math basic: Provides basic math calculations and operations.
  • Bits and Bytes: Provides various bit and byte get and set functions.
  • Random Numbers: Pseudo random number function library, using randomSeed() to assign a seed and random() to get the random number.
  • Trigonometry: Radian based trig functions sin(), cos() and tan().
 

Functions
Function 
Description 
The random function generates pseudo-random numbers. 
The random function generates pseudo-random numbers. 
randomSeed() initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. 
sqrt 
Calculates the square root of a number. 
map 
Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc. 
pow 
Calculates the value of a number raised to a power. Pow() functiom can be used to raise a number to a fractional power. This is useful for generating exponential mapping of values or curves. 
cos 
Calculates the cosine of an angle (in radians). The result will be between -1 and 1. 
sin 
Calculates the sine of an angle (in radians). The result will be between -1 and 1. 
tan 
Calculates the tangent of an angle (in radians). The result will be between negative infinity and infinity. 
Macros
Macro 
Description 
bit 
Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.). 
Clears (writes a 0 to) a bit of a numeric variable. 
Reads a bit of a number. 
Sets (writes a 1 to) a bit of a numeric variable. 
Writes a bit of a numeric variable. 
Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type). 
Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type). 
abs 
Computes the absolute value of a number. 
Constrains a number to be within a range. 
max 
Calculates the maximum of two numbers. 
min 
Calculates the minimum of two numbers. 
Links