06 May 2016
17.2.1 Quick connection of the math module to RCML
The math functional module is used to access mathematical functions similar to those in the math.h library in C++.
 To include the math module, add an entry to section [function_modules] in the RCML configuration file in accordance with Section "Installation and Configuration of RCML Compiler and Interpreter". The module does not require additional configuration.
 Now, there are the following functions at your disposal:
Definition 
Description 
An exception is thrown, if 

pow(a, b) 
Powering a to power b. 


sqrt(a) 
Returns square root of a; a cannot be less than 0. 
a < 0 

abs(a) 
Returns the absolute value of a. 


rand(a,b) 
Returns a random integer in the range [b; a+b]; a cannot be less than or equal to 0. 
a ≤ 0 

sin(a) 
Functions sin, cos, tan accept values in radians. 
Returns the sine of a. 

cos(a) 
Returns the cosine of a. 


tan(a) 
Returns the tangent of a. 


asin(a) 
Returns the arcsine of a. Because of the function properties, argument a must be within [1; 1]. 
Functions asin, acos, atan return values in radians. 
a ∉ [1;1] 
acos(a) 
Returns the arc cosine of a. Because of the function properties, argument a must be within [1; 1]. 
a ∉ [1;1] 

atan(a) 
Returns the arc tangent of a. 


exp(a) 
Returns e to power a. 


log(a) 
Returns the natural logarithm of a. Because of the function properties, argument a must be more than 0. 
a ≤ 0 

log10(a) 
Returns the decimal logarithm of a. Because of the function properties, argument a must be more than 0. 
a ≤ 0 
 In accordance with Section "Calling Functions", the syntax of the program using the math module is as follows:
function main() {
r = 9;
r = math.sqrt(r);
system.echo(r);
}
The result of running this program is number 3.0000
 The following example shows throwing an exception in case of incorrect input data.
function main() {
try {
r=math.log(0);
} catch {
system.echo("Throw exception log(0) undefined");
}
}
More detail about using exceptions is available in section "Exceptions".