Caché MultiValue Basic Reference
PWRS


Returns the elements of a dynamic array raised to a power.
Synopsis
Arguments
Description
The
PWRS function raises each element of
dynarray to the power specified by the corresponding element of the
exponents dynamic array. Both numeric values can be expressed as either numbers or as strings. Leading plus signs and leading and trailing zeros are ignored. A string is parsed as a number until a nonnumeric character is encountered. Thus “7dwarves” is parsed as 7.
If the two dynamic arrays have different numbers of elements, by default the shorter dynamic array) is padded so that the returned dynamic array has the number of elements of the longer dynamic array. If the shorter dynamic array is the value to be raised, it is padded with the required number of elements with the value of 0. If the shorter dynamic array is the exponents, it is padded with the required number of elements with the value of 1. You can also use the
REUSE function to define behavior when specifying two dynamic arrays with different numbers of elements.
Note:
In the
exponents dynamic array, missing elements and elements with a null string or nonnumeric string value are parsed as 1. This parsing differs from the
PWR function and other MultiValue numeric functions and operators, which parse nonnumerics as 0.
Any nonzero numeric element value raised to an exponent of 0 returns 1. If the corresponding
dynarray and
exponents elements are both 0,
PWRS returns 0 for that element. If the
dynarray element is 0 and the corresponding
exponents element is a negative number,
PWRS generates an <ILLEGAL VALUE> error. If the
dynarray element is a negative number and the corresponding
exponents element is a fractional number,
PWRS generates an <ILLEGAL VALUE> error.
A very large positive
exponents element value (such as 135), or a very small
dynarray element value (such as .00005) with a corresponding negative
exponents element (such as 30) may result in an overflow, generating a <MAXNUMBER> error. A very large negative
exponents element value (such as 135), or a very small
dynarray element value (such as .00005) with a corresponding positive
exponents element (such as 30) may result in an underflow, returning 0.
To return the exponent of a single value raised to a power, use the
PWR function or the
** operator.
Example
The following example returns the value of each element in
mynums raised to the corresponding element in
myexps:
mynums=1:@VM:2:@VM:3:@VM:4:@VM:5
myexps=2:@VM:3:@VM:2:@VM:3:@VM:2
crt PWRS(mynums,myexps)
! returns: 1ý8ý9ý64ý25
See Also