13 #include "cl_rational.h"
14 #include "cl_integer.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_R expt_pos (const cl_R& x, uintL y)
32 return expt(x,y); // x rational -> schnellere Routine
37 while (!(b % 2)) { a = square(a); b = b >> 1; }
42 if (b % 2) { c = a * c; }
48 const cl_R expt (const cl_R& x, sintL y)
50 if (y==0) { return 1; } // y=0 -> Ergebnis 1
51 var uintL abs_y = (y<0 ? (uintL)(-y) : y); // Betrag von y nehmen
52 var cl_R z = expt_pos(x,abs_y); // (expt x (abs y))
53 return (y<0 ? recip(z) : z); // evtl. noch Kehrwert nehmen