Flexs Q5 Pro
/ Math & Utilities
/ Math
Math
Standard JavaScript Math library plus embedded extensions: Math.map() scaling and a hardware random number generator.
The standard JavaScript Math library is available, with two embedded
specialties documented below: Math.map() for scaling sensor values and
Math.random() backed by the hardware random number generator.
Constants: Math.E (β2.718), Math.LN10 (β2.303), Math.LN2 (β0.693),
Math.LOG10E (β0.434), Math.LOG2E (β1.443), Math.PI (β3.14159),
Math.SQRT1_2 (β0.707), Math.SQRT2 (β1.414).
Standard methods: abs, acos, acosh, asin, asinh, atan,
atan2, atanh, cbrt, ceil, cos, cosh, exp, floor, log ,
max, min, pow, round, sin, sinh, sqrt, tan, tanh, trunc β
all behave as in standard JavaScript.
Functions
Math.random() β Returns a 32-bit random number from the hardware random number generator.
Math.abs() β Returns the absolute value of x.
Math.acos() β Returns the arccosine of x.
Math.acosh() β Returns the hyperbolic arccosine of x.
Math.asin() β Returns the arcsine of x.
Math.asinh() β Returns the hyperbolic arcsine of a number.
Math.atan() β Returns the arctangent of x.
Math.atan2() β Returns the arctangent of the quotient of its arguments.
Math.atanh() β Returns the hyperbolic arctangent of x.
Math.cbrt() β Returns the cube root of x.
Math.ceil() β Returns the smallest integer greater than or equal to x.
Math.cos() β Returns the cosine of x.
Math.cosh() β Returns the hyperbolic cosine of x.
Math.exp() β Returns e^x, where e is Euler's number.
Math.floor() β Returns the largest integer less than or equal to x.
Math.log() β Returns the natural logarithm (base e) of x.
Math.max() β Returns the largest of zero or more numbers.
Math.min() β Returns the smallest of zero or more numbers.
Math.pow() β Returns base x to the exponent power y.
Math.round() β Returns the value of x rounded to the nearest integer.
Math.sin() β Returns the sine of x.
Math.sinh() β Returns the hyperbolic sine of x.
Math.sqrt() β Returns the positive square root of x.
Math.tan() β Returns the tangent of x.
Math.tanh() β Returns the hyperbolic tangent of x.
Math.trunc() β Returns the integer portion of x, removing any fractional digits.
Math.random() β number
Returns a 32-bit random number from the hardware random number generator.
Unlike standard JavaScript, Math.random() on the Q5C is backed by the
hardware random number generator, making it suitable for nonces and keys.
Returns
number
32-bit hardware random number.
Example
Copy
let nonce = Math.random();
Math.abs(x) β number
Returns the absolute value of x.
Returns x without its sign. Negative values become positive; positive values and zero are returned unchanged.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The absolute value of x.
Example
Copy
let d = Math.abs(-5); // 5
Math.acos(x) β number
Returns the arccosine of x.
Returns the angle, in radians, whose cosine is x. The result is in the range 0 to Ο. Returns NaN if x is outside -1 to 1.
Arguments
Name Type Required Default Description
x
number
optional
β
A number between -1 and 1.
Returns
number
The arccosine of x, in radians.
Example
Copy
let a = Math.acos(0.5); // 1.0471975511965979
Math.acosh(x) β number
Returns the hyperbolic arccosine of x.
Returns the hyperbolic arccosine of x. Returns NaN if x is less than 1.
Arguments
Name Type Required Default Description
x
number
optional
β
A number greater than or equal to 1.
Returns
number
The hyperbolic arccosine of x.
Example
Copy
let a = Math.acosh(2); // 1.3169578969248166
Math.asin(x) β number
Returns the arcsine of x.
Returns the angle, in radians, whose sine is x. The result is in the range -Ο/2 to Ο/2. Returns NaN if x is outside -1 to 1.
Arguments
Name Type Required Default Description
x
number
optional
β
A number between -1 and 1.
Returns
number
The arcsine of x, in radians.
Example
Copy
let a = Math.asin(1); // 1.5707963267948966
Math.asinh(x) β number
Returns the hyperbolic arcsine of a number.
Returns the hyperbolic arcsine of x.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The hyperbolic arcsine of x.
Example
Copy
let a = Math.asinh(1); // 0.881373587019543
Math.atan(x) β number
Returns the arctangent of x.
Returns the angle, in radians, whose tangent is x. The result is in the range -Ο/2 to Ο/2.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The arctangent of x, in radians.
Example
Copy
let a = Math.atan(1); // 0.7853981633974483
Math.atan2(y, x) β number
Returns the arctangent of the quotient of its arguments.
Returns the angle, in radians, between the positive x-axis and the point (x, y). Note the argument order: y comes first. The result is in the range -Ο to Ο, and the signs of both arguments are used to determine the quadrant.
Arguments
Name Type Required Default Description
y
number
optional
β
The y coordinate.
x
number
optional
β
The x coordinate.
Returns
number
The angle in radians between the positive x-axis and the point (x, y).
Example
Copy
let heading = Math.atan2(1, 1); // 0.7853981633974483
Math.atanh(x) β number
Returns the hyperbolic arctangent of x.
Returns the hyperbolic arctangent of x. Returns Infinity or -Infinity for 1 and -1, and NaN if x is outside that range.
Arguments
Name Type Required Default Description
x
number
optional
β
A number between -1 and 1.
Returns
number
The hyperbolic arctangent of x.
Example
Copy
let a = Math.atanh(0.5); // 0.5493061443340548
Math.cbrt(x) β number
Returns the cube root of x.
Returns the cube root of x. Unlike Math.sqrt() , negative values are allowed and return a negative result.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The cube root of x.
Example
Copy
let c = Math.cbrt(27); // 3
Math.ceil(x) β number
Returns the smallest integer greater than or equal to x.
Rounds x up to the next integer. Integers are returned unchanged.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The smallest integer greater than or equal to x.
Example
Copy
let c = Math.ceil(4.2); // 5
Math.cos(x) β number
Returns the cosine of x.
Returns the cosine of the angle x, given in radians. The result is in the range -1 to 1.
Arguments
Name Type Required Default Description
x
number
optional
β
An angle in radians.
Returns
number
The cosine of x.
Example
Copy
let c = Math.cos(Math.PI); // -1
Math.cosh(x) β number
Returns the hyperbolic cosine of x.
Returns the hyperbolic cosine of x.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The hyperbolic cosine of x.
Example
Copy
let c = Math.cosh(1); // 1.5430806348152437
Math.exp(x) β number
Returns e^x, where e is Euler's number.
Returns e raised to the power of x, where e is Euler's number (approximately 2.718), the base of the natural logarithm.
Arguments
Name Type Required Default Description
x
number
optional
β
The exponent.
Returns
number
e raised to the power x.
Example
Copy
let e = Math.exp(1); // 2.718281828459045
Math.floor(x) β number
Returns the largest integer less than or equal to x.
Rounds x down to the previous integer. Integers are returned unchanged. For negative values this rounds away from zero; use Math.trunc() to round toward zero.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The largest integer less than or equal to x.
Example
Copy
let f = Math.floor(4.8); // 4
Math.log(x) β number
Returns the natural logarithm (base e) of x.
Returns the natural logarithm (γ) of x. Returns -Infinity for 0 and NaN for negative values.
Arguments
Name Type Required Default Description
x
number
optional
β
A number greater than or equal to 0.
Returns
number
The natural logarithm of x.
Example
Copy
let l = Math.log(Math.E); // 1
Math.max(...values) β number
Returns the largest of zero or more numbers.
Returns the largest of the given numbers. Returns -Infinity if no arguments are given, and NaN if any argument is NaN.
Arguments
Name Type Required Default Description
...values
number
optional
β
Zero or more numbers to compare.
Returns
number
The largest of the given numbers.
Example
Copy
let hi = Math.max(3, 9, 4); // 9
Math.min(...values) β number
Returns the smallest of zero or more numbers.
Returns the smallest of the given numbers. Returns Infinity if no arguments are given, and NaN if any argument is NaN.
Arguments
Name Type Required Default Description
...values
number
optional
β
Zero or more numbers to compare.
Returns
number
The smallest of the given numbers.
Example
Copy
let lo = Math.min(3, 9, 4); // 3
Math.pow(x, y) β number
Returns base x to the exponent power y.
Returns x raised to the power y (that is, x^y).
Arguments
Name Type Required Default Description
x
number
optional
β
The base.
y
number
optional
β
The exponent.
Returns
number
x raised to the power y.
Example
Copy
let p = Math.pow(2, 10); // 1024
Math.round(x) β number
Returns the value of x rounded to the nearest integer.
Rounds x to the nearest integer. Values with a fractional part of exactly 0.5 are rounded up toward positive infinity, so Math.round(-2.5) returns -2.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
x rounded to the nearest integer.
Example
Copy
let r = Math.round(4.5); // 5
Math.sin(x) β number
Returns the sine of x.
Returns the sine of the angle x, given in radians. The result is in the range -1 to 1.
Arguments
Name Type Required Default Description
x
number
optional
β
An angle in radians.
Returns
number
The sine of x.
Example
Copy
let s = Math.sin(Math.PI / 2); // 1
Math.sinh(x) β number
Returns the hyperbolic sine of x.
Returns the hyperbolic sine of x.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The hyperbolic sine of x.
Example
Copy
let s = Math.sinh(1); // 1.1752011936438014
Math.sqrt(x) β number
Returns the positive square root of x.
Returns the positive square root of x. Returns NaN for negative values.
Arguments
Name Type Required Default Description
x
number
optional
β
A number greater than or equal to 0.
Returns
number
The positive square root of x.
Example
Copy
let s = Math.sqrt(16); // 4
Math.tan(x) β number
Returns the tangent of x.
Returns the tangent of the angle x, given in radians.
Arguments
Name Type Required Default Description
x
number
optional
β
An angle in radians.
Returns
number
The tangent of x.
Example
Copy
let t = Math.tan(Math.PI / 4); // 0.9999999999999999
Math.tanh(x) β number
Returns the hyperbolic tangent of x.
Returns the hyperbolic tangent of x. The result is in the range -1 to 1.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The hyperbolic tangent of x.
Example
Copy
let t = Math.tanh(1); // 0.7615941559557649
Math.trunc(x) β number
Returns the integer portion of x, removing any fractional digits.
Removes the fractional part of x, rounding toward zero. Unlike Math.floor() , negative values are rounded up.
Arguments
Name Type Required Default Description
x
number
optional
β
A number.
Returns
number
The integer part of x.
Example
Copy
let t = Math.trunc(-4.7); // -4