Next: , Previous: , Up: Built-in functions   [Contents][Index]


Integer functions

Integer functions

ABS returns the absolute value of its argument. For example, ‘ABS(99)’ and ‘ABS(-99)’ are both ‘99’.

BITS returns the minimum number of bits needed to store its argument. For example, ‘BITS(12345)’ is ‘14’ because 2^14 is 16,384, which is larger than 12,345, while 2^13 is 8,192, which is too small. ‘BITS(0)’ is defined to be ‘0’. Essentially, ‘BITS(x)’ represents the ceiling of the base-2 logarithm of x. Negative numbers are treated as their two’s-complement equivalent. For example, ‘BITS(-1)’ returns ‘32’ on a 32-bit system and ‘64’ on a 64-bit system.

CBRT is an integer cube root function. It is essentially just syntactic sugar for the more general ROOT function: ‘CBRT(x)’ = ROOT(3, x).

FACTOR10 rounds its argument down (more precisely, towards zero) to the largest single-digit factor of an integral power of 10.FACTOR10(4975)’ is therefore ‘4000’. Similarly, ‘FACTOR10(-4975)’ is ‘-4000’.

LOG10(x)’ is the floor of the base-10 logarithm of x. For instance, ‘LOG10(12345) is ‘4’ because 10^4 is the largest integral power of 10 that does not exceed 12,345.

MIN and MAX return, respectively, the minimum and maximum value in a list of numbers. Unlike the other built-in functions, MIN and MAX accept an arbitrary number of arguments (but at least one). For example, ‘MIN(8,6,7,5,3,0,9)’ is ‘0 and ‘MAX(8,6,7,5,3,0,9)’ is ‘9’.

ROOT(n, x)’ returns the nth root of x. More precisely, it returns the largest integer r such that r^n <= x. ROOT is not currently defined on negative values of x. As an example of ROOT usage, ‘ROOT(5, 245)’ is ‘3’ because 3^5 = 243 <= 245 while 4^5 = 1024 > 245. Similarly, ‘ROOT(2, 16)’ =4’; ‘ROOT(3, 27)’ =3’; ‘ROOT(0, 0)’ and ‘ROOT(4, -245)’ each return a run-time error; and, ‘ROOT(-3, 8)’ = 0’ (because ‘ROOT(-3, 8)’ = 1/ROOT(3, 8)’ = 1/2’ = ‘0’).

SQRT is an integer square root function. It is essentially just syntactic sugar for the more general ROOT function: ‘SQRT(x)’ = ROOT(2, x).


Next: , Previous: , Up: Built-in functions   [Contents][Index]

Scott Pakin, pakin@lanl.gov