7 #include "cl_complex.h"
19 // Solange b gerade, setze a:=a*a, b:=b/2. [a^b bleibt invariant, = x^y.]
21 // Solange b:=floor(b/2) >0 ist,
22 // setze a:=a*a, und falls b ungerade, setze c:=a*c.
24 // Für y=0: Ergebnis 1.
25 // Für y<0: (/ (expt x (- y))).
28 inline const cl_N expt_pos (const cl_N& x, const cl_I& y)
32 while (!oddp(b)) { a = square(a); b = b >> 1; }
37 if (oddp(b)) { c = a * c; }
42 const cl_N expt (const cl_N& x, const cl_I& y)
46 // x reell -> schnellere Routine
49 if (eq(y,0)) { return 1; } // y=0 -> Ergebnis 1
50 var cl_boolean y_negative = minusp(y);
51 var cl_I abs_y = (y_negative ? -y : y); // Betrag von y nehmen
52 var cl_N z = expt_pos(x,abs_y); // (expt x (abs y))
53 return (y_negative ? recip(z) : z); // evtl. noch Kehrwert nehmen