Using Caché ObjectScript - InterSystems Documentation
Using Caché ObjectScript - InterSystems Documentation
Using Caché ObjectScript - InterSystems Documentation
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Arithmetic Operators<br />
5.2.7 Exponentiation Operator (**)<br />
The Exponentiation Operator produces the exponentiated value of the left operand raised to the power of the right operand.<br />
• 0**0: Zero raised to the power of zero is 0. However, if either operand is an IEEE double-precision number, (for<br />
example, 0**$DOUBLE(0) or $DOUBLE(0)**0) zero raised to the power of zero is 1. For further details, refer to<br />
the $DOUBLE function.<br />
• 0**n: 0 raised to the power of any positive number n is 0. This includes 0**$DOUBLE("INF"). Attempting to raise<br />
0 to the power of a negative number results in an error: <strong>Caché</strong> negative numbers generate an <br />
error; $DOUBLE negative numbers generate a error.<br />
• num**0: Any non-zero number (positive or negative) raised to the power of zero is 1. This includes<br />
$DOUBLE("INF")**0.<br />
• 1**n: 1 raised to the power of any number (positive, negative, or zero) is 1.<br />
• -1**n: -1 raised to the power of zero is 1. -1 raised to the power of 1 or -1 is -1. For exponents larger than 1, see<br />
below.<br />
• num**n: A positive number (integer or fractional) raised to any power (integer or fractional, positive or negative)<br />
returns a positive number.<br />
• -num**n: A negative number (integer or fractional) raised to the power of an even integer (positive or negative)<br />
returns a positive number. A negative number (integer or fractional) raised to the power of an odd integer (positive or<br />
negative) returns a negative number.<br />
• -num**.n: Attempting to raise a negative number to the power of a fractional number results in an error.<br />
• $DOUBLE("INF")**n: An infinite number (positive or negative) raised to the power of 0 is 1. An infinite number<br />
(positive or negative) raised to the power of any positive number (integer, fractional, or INF) is INF. An infinite<br />
number (positive or negative) raised to the power of any negative number (integer, fractional, or INF) is 0.<br />
• $DOUBLE("NAN"): NAN on either side of the exponentiation operator always returns NAN, regardless of the value<br />
of the other operand.<br />
Very large exponents may result in overflow and underflow values:<br />
• num**nnn: A positive or negative number greater than 1 with a large positive exponent value (such as 9**153 or<br />
-9.2**152) generates a error.<br />
• num**-nnn: A positive or negative number greater than 1 with a large negative exponent value (such as 9**-135<br />
or -9.2**-134) returns 0.<br />
• .num**nnn: A positive or negative number less than 1 with a large positive exponent value (such as .22**196 or<br />
-.2**184) returns 0.<br />
• .num**-nnn: A positive or negative number less than 1 with a large negative exponent value (such as .22**-196<br />
or -.2**-184) generates a error.<br />
An exponent that exceeds the maximum value supported by <strong>Caché</strong> numbers either issues a error or<br />
automatically converts to an IEEE double-precision floating point number. This automatic conversion is specified by using<br />
either the TruncateOverflow() method of the %SYSTEM.Process class on a per-process basis, or the TruncateOverflow<br />
property of the Config.Miscellaneous class on a system-wide basis. For further details, refer to the $DOUBLE function.<br />
The following examples performs exponentiation on two numeric literals:<br />
Write "9 ** 2 = ",9 ** 2,! // 81<br />
Write "9 ** -2 = ",9 ** -2,! // .01234567901234567901<br />
Write "9 ** 2.5 = ",9 ** 2.5,! // 242.9999999994422343<br />
<strong>Using</strong> <strong>Caché</strong> <strong>ObjectScript</strong> 39