From: John H Meyers <jhmeyers@mum.edu>
Subject: Exact, real-valued, rational power function

RatPower (Rational, real-valued power of real args)

The purpose of this function is to resolve desires for
a function which will compute exact real-valued answers
(with correct sign) to, say '(-8)^(5/3)' ==> -32
rather than the usual slightly inexact and possibly
complex-valued result, which arises when the power
is truncated to a fixed number of decimal places,
and/or the first argument is negative, e.g.

8 1.66666666667 ^ ==> 32.0000000002

-8 1.66666666667 ^ ==> (16.0000000004, -27.7128129211)


The required arguments are (stack version):

 Real or Symbolic [level 2]

 Real or fraction [level 1]


\<< \->NUM DUP SIGN SWAP ABS \->Q
 IF DUP TYPE THEN OBJ\-> DROP2 { XROOT } +
 ELSE { } END 4 ROLLD * ^ SWAP EVAL \>>


Examples:

-8 '2/3' ==> 4

-32 -.6 ==> -.125

'X' 5 ==> 'X^5'

'X' '1/3' ==> 'XROOT(3,X)'

'X' '2/3' ==> 'XROOT(3,X^2)'

'X' -.2 ==> 'XROOT(5,INV(X))'

'X' -.4 ==> 'XROOT(5,X^-2)'


Don't expect miracles from this simplistic program,

e.g. 2 3.14159265359 ==> (a wrong result)

because of an overflow during 'XROOT(364913,2^1146408)'
[which you can error-trap by setting flags -20 and -21]

-----------------------------------------------------------
With best wishes from: John H Meyers <jhmeyers@mum.edu>
