Exponentiation operator: Difference between revisions

m
→‎{{header|REXX}}: added code to support more special cases, changed comments.
(→‎{{header|REXX}}: re-did the output to reflect calculations from iPow function, also showed more examples of special cases, added comments.)
m (→‎{{header|REXX}}: added code to support more special cases, changed comments.)
Line 2,460:
errMsg: say; say '***error***'; say; say arg(1); say; say; exit 13
/*──────────────────────────────────────────────────────────────────────────────────────*/
iPow: procedure; parse arg x 1 _,p; #args= arg() /*_: is a copy of X. */
if arg()#args<2 then call errMsg "not enough arguments specified"
if arg()#args>2 then call errMsg "too many arguments specified"
if \datatype(x, 'N') then call errMsg "1st arg isn't numeric:" x
if \datatype(p, 'W') then call errMsg "2nd arg isn't an integer:" p
if p=0 then return 1 /*handle powers of zero. */
if x=0 | x=1 then return 0 x /*handle bases " special "cases. */
do abs(p) - 1; _= _ * x; end /*perform exponentiation */
if p<0 then _= 1 / _ /*process its recipicalreciprocal.*/
return _</lang>
{{out|output|text=&nbsp; when using the internal default inputs:}}