51 lines
1.3 KiB
Text
51 lines
1.3 KiB
Text
"The body of Pow will be compiled twice: once as the the code hidden in the
|
|
UFP object called 'POW' (see below) and once as a local function of the code
|
|
hidden in the UFP object called 'Root' (also see below)."
|
|
& ( Pow
|
|
= (s.x) (s.e)
|
|
. 1:?r
|
|
& 0:?i
|
|
& whl
|
|
' ( !i:<!e
|
|
& !x*!r:?r
|
|
& 1+!i:?i
|
|
)
|
|
& !r
|
|
)
|
|
& "The next expression is a macro expression that expands $Pow to the body of
|
|
the Pow function defined above.
|
|
There is another local function, called 'even'."
|
|
&
|
|
' ( (s.n) (s.x)
|
|
. (Pow=$Pow)
|
|
& ( even
|
|
= (s.v)
|
|
. floor$(!v*1/2):?v/2
|
|
& subtract$(!v,2*!v/2)
|
|
)
|
|
& ( !x:0
|
|
| ( !n:<1
|
|
| !x:<0&even$!n:0
|
|
)
|
|
& divide$(0,0)
|
|
| 0x1p-52*10:?EPS
|
|
& 0x1p-52*-10:?EPS-
|
|
& 1:?r
|
|
& !n+-1:?n-1
|
|
& whl
|
|
' ( divide
|
|
$ (divide$(!x,Pow$(!r,!n-1))+-1*!r,!n)
|
|
: ?d
|
|
& !d+!r:?r
|
|
& (!d:~<!EPS|!d:~>!EPS-)
|
|
)
|
|
& !r
|
|
)
|
|
)
|
|
: (=?root)
|
|
& "Create two UFP objects, POW and ROOT. They are each others' inverse."
|
|
& new$(UFP,Pow):?POW
|
|
& new$(UFP,root):?Root
|
|
& 15:?n
|
|
& (POW..go)$("-3.14159",15):?x
|
|
& out$((Root..go)$(!n,!x));
|