Newer Version Available
Math Functions
You can use SAQL math functions in foreach statements and in the filter by clause after a foreach statement.
You can't use math functions in a group by clause or in an order by clause. You also can't use math functions in the filter by clause before a foreach statement, but you can use them after the foreach statement.
Functions
| Function | Description |
|---|---|
| abs(n) | Returns the absolute number of n as a
numeric value. n can be any real numeric
value in the range of -1e308 <= n <=
1e308. This example is
valid:
These
examples are
invalid:
|
| ceil(n) | Returns the nearest integer of equal or greater value to
n. n can be any real
numeric value in the range of -1e308 <= n <=
1e308. This example is
valid:
These
examples are
invalid:
|
| floor(n) | Returns the nearest integer of equal or lesser value to
n. n can be any real
numeric value in the range of -1e308 <= n <=
1e308. This example is
valid:
These
examples are
invalid:
|
| trunc(n[, m]) | Returns the value of the numeric expression
n truncated to m
decimal places. m can be negative, in which
case the function returns n truncated to
-m places to the left of the decimal
point. If m is omitted, it returns
n truncated to the integer place.
n can be any real numeric value in the
range of -1e308 <= n <= 1e308. m can be
an integer value between -15 and 15 inclusive. This example is
valid:
These
examples are
invalid:
|
| round(n[, m]) | Returns the value of n rounded to
m decimal places. m
can be negative, in which case the function returns
n rounded to -m places
to the left of the decimal point. If m is
omitted, it returns n rounded to the nearest
integer. For tie-breaking, it follows round half way from zero
convention. n can be any real numeric value
in the range of -1e308 <= n <= 1e308. m
can be an integer value between -15 and 15, inclusive. This example is
valid:
These examples are invalid:
|
| exp(n) |
Returns the value of Euler's number e raised to the power of n, where e = 2.71828183… The smallest value for n that will not result in 0 is 3e-324. n can be any real numeric value in the range of -1e308 <= n <= 700. These examples are
valid:
These examples are
invalid:
|
| log(m, n) |
Returns the natural logarithm (base m) of a number n. The values m and n can be any positive, non-zero numeric value in the range 0 < m, n <= 1e308 and m ≠ 1. The smallest number input allowed for m is >0, m!=1. The smallest number for m or n that will not produce 0 is log(10, 0.3e-323). These examples are
valid:
These examples are
invalid:
|
| power(m, n) |
Returns m raised to the nth power. m, n can be any numeric value in the range of -1e308 <= m, n <= 1e308. Returns null if m = 0 and n < 0.
These examples are
valid:
These examples are
invalid:
|
| sqrt(n) |
Returns the square root of a number n. The value n can be any non-negative numeric value in the range of 0 <= n <= 1e308. These examples are
valid:
These examples are
invalid:
|