Math Functions
Spectre expressions support the following standard math functions. These functions can be used in all Spectre file types.
abs(value : numeric) : double
For example:
`abs(2)` returns 2
`abs(-2)` returns 2
`abs(2.3)` returns 2.3
`abs(-2.3)` returns 2.3
`abs(77.5)` returns 77.5
`abs(-0.62)` returns 0.62
`abs(calc("Value") - 1600)`returns 91.4484 when Value is 1508.5516
arccos(value : numeric) : double
For example:
`arccos(45)` returns <error>
`arccos(0.45)` returns 1.104030
`arccos(calc("Value") / 2000)` returns 0.7162459 when Value is 1508.5516
arcsin(value : numeric) : double
For example:
`arcsin(calc("Value") / 2000)` returns 0.8545504 when Value is 1508.5516
arctan(value : numeric) : double
For example:
`arctan(calc("Value") / 2000)` returns 0.646232 when Value is 1508.5516
For example:
`ceil(2.3)` returns 3
`ceil(2.7)` returns 3
`ceil(-2.3)` returns -2
`ceil(-2.7)` returns -2
`ceil(calc("Value"))` returns -91 when the Value is -91.4484
cos(angle_radians : numeric) : double
For example:
`cos(100)` returns 0.862319
`cos(45)` returns 0.525322
`cos(0.45)` returns 0.900447
`cos(calc("Value"))` returns 0.8325361 when Value is 1508.5516
exp(exponent : numeric) : double
For example:
`exp(calc("Value") / 1000)` returns 4.520179 for a Value of 1508.5516
`exp(20 / 1000)` returns 1.0202013
floor(value : numeric) : double
For example:
`floor(2.3)` returns 2
`floor(2.7)` returns 2
`floor(-2.3)` returns -3
`floor(calc("Value"))` returns -92 when the Value is -91.4484
insert_decimal(number : numeric, places : integer) : double
For example:
`insert_decimal(2891, 3)` returns 2.891
`insert_decimal(1000, 6)` returns 0.001
`insert_decimal(4567, 6)` returns 0.004567
`insert_decimal(5, 4)` returns 0.0005
ln(value : numeric) : double
For example:
`ln(100)` returns 4.605200
`ln(1)` returns 0
`ln(100000)` returns 11.512900
`ln(0)` returns <error>
`ln(calc("Value"))` returns 7.3189053 for a Value of 1508.5516
log10(value : numeric) : double
For example,
`log10(100)` returns 2.0
`log10(1)` returns 0.0
`log10(100000)` returns 5.0
`log10(10)` returns 1.0
`log10(0)` returns <error>
`log10(calc("Value"))` returns 3.1785602 for a Value of 1508.5516
max(value1 : any, value2 : any, ... : any) : any
For example:
`max(value("cost"), value("price"), value("discount"))` returns, for each row, the largest value found in the three named columns
`max(calc("Value"), 1700)` returns the greater of the calculation or 1700
max(expression: any) : any
For example:
`max(value("Price"))` returns the maximum value in the Price column
min(value1 : any, value2 : any, ... : any) : any
For example:
`min(value("cost"), value("price"), value("discount"))` returns, for each row, the smallest value found in the three named columns
`min(calc("Value"), 1600)` returns the lesser of the calculation or 1600
min(expression : any) : any
For example:
`min(value("Price"))` returns the minimum value in the Price column
mod(dividend : numeric, divisor : numeric) : double
For example:
`mod(10, 3)` returns 1
`mod(20, 5)` returns 0
`mod(48, 55, 12)` returns 0.55
`mod(calc("Value"), 123.4)` returns 27.7516 for a Value of 1508.5516
pct_var(newer_value : numeric, older_value : numeric) : double
For example:
`pct_var(2,1)` returns 100
`pct_var(3,4)` returns -25
`pct_var(1,0)` returns null
pow(base : numeric, exponent : numeric) : double
For example:
`pow(8, 3)` returns 512
`pow(3, 12)` returns 531441
`pow(calc("Value"), 1.5)` returns 58592.2606643 for a Value of 1508.5516
random() : double
For example:
`random()` could return 0.221034
When a calculation with a random number (`random()`) is made in a cPlan, this function generates a random number for each line.
round(value : numeric, unit : numeric) : double
For example:
`round(0.2)` returns 0
`round(0.49)` returns 0
`round(0.5)` returns 1
`round(0.9)` returns 1
`round(-0.5)` returns -1
`round(0.49, 0.1)` returns 0.5
`round(3.1415926, 0.000001)` returns 3.141593
`round(-55, 100)` returns -100
`round(17, 5)` returns 15
`round(calc("Value"))` returns -91.0 when the Value is -91.4484
sign(value : numeric) : double
For example:
`sign(-99)` returns -1
`sign(0.1)` returns 1
`sign(0)` returns 0
`sign(calc("Value") - 1600)`returns -1 when the Value is 1508.5516
sin(angle_radians : numeric) : double
For example:
`sin(1508.5516)` returns 0.5539708
`sin(calc("Value"))` returns 0.5539708 when Value is 1508.5516
sqrt(value : numeric) : double
For example:
`sqrt(25)` returns 5.0
`sqrt(30)` returns 5.4772256
`sqrt(175)` returns 13.22887566
`sqrt(0.45)` returns 0.6708204
`sqrt(-1)` returns <error>
`sqrt(calc("Value"))` returns 38.8400772 for a Value of 1508.5516
tan(angle_radians : numeric) : double
For example:
`tan(2007.396)` returns -0.0818879
`tan(calc("Value"))` returns 0.6654016 when Value is 1508.5516
trunc(value : numeric) : double
For example:
`trunc(2.3)` returns 2.0
`trunc(2.7)` returns 2.0
`trunc(-2.3)` returns -2.0
`trunc(-2.7)` returns -2.0
`trunc(calc("Value"))` returns -91.0 when the Value is -91.4484
See also: Alphabetized Functions for Spectre.