Skip to main content

$ZPOWER (ObjectScript)

Returns the value of a number raised to a specified power.

Synopsis

$ZPOWER(num,exponent)

Arguments

Argument Description
num The number to be raised to a power.
exponent The exponent.

Description

$ZPOWER returns the value of the num argument raised to the nth power.

This function performs the same operation as the Exponentiation operator (**). For details on valid operands and the value returned for specific combinations of values, see Exponentiation Operator.

Arguments

num

The number to be raised to a power. It can be integer or floating point, negative, positive, or zero. It can be a standard InterSystems IRIS number or an IEEE double-precision binary floating-point number (a $DOUBLE number). It can be specified as a value, a variable, or an expression.

If you specify num as a quoted string, the string is parsed as a number, as described in Strings as Numbers. The null string ("") and non-numeric strings evaluate to zero.

exponent

The exponent is a number that can be integer or floating point, negative, positive, or zero. It can be a standard InterSystems IRIS number or an IEEE double-precision binary floating-point number (a $DOUBLE number). It can be specified as a numeric or string value, a variable, or an expression.

If you specify exponent as a quoted string, the string is parsed as a number, as described in Strings as Numbers. The null string ("") and non-numeric strings evaluate to zero.

The following combinations of num and exponent result in an error:

  • If num is negative, exponent must be an integer. Otherwise an <ILLEGAL VALUE> error is generated.

  • If num is 0, exponent must be a positive number or zero. Otherwise an <ILLEGAL VALUE> or <DIVIDE> error is generated.

  • Large exponent values, such as $ZPOWER(9,153) may result in an overflow, generating a <MAXNUMBER> error, or may result in an underflow, returning 0. Which result occurs depends on whether num is greater than 1 (or -1), and whether exponent is positive or negative. A <MAXNUMBER> error occurs when an operation exceeds the largest number that InterSystems IRIS supports. For further details, refer to Extremely Large Numbers.

For further details on valid operands and the value returned for specific combinations of values, see Exponentiation Operator.

Examples

The following example raises 2 to the first ten powers:

  SET x=0
  WHILE x < 10 {
    SET rtn=$ZPOWER(2,x)
    WRITE !,"The ",x," power of 2=",rtn
    SET x=x+1 }

See Also

FeedbackOpens in a new tab