4 #include "base/cl_sysdep.h"
12 #include "real/cl_R.h"
13 #include "cln/rational.h"
14 #include "cln/integer.h"
15 #include "integer/cl_I.h"
22 // Solange b gerade, setze a:=a*a, b:=b/2. [a^b bleibt invariant, = x^y.]
24 // Solange b:=floor(b/2) >0 ist,
25 // setze a:=a*a, und falls b ungerade, setze c:=a*c.
27 // Für y=0: Ergebnis 1.
28 // Für y<0: (/ (expt x (- y))).
31 inline const cl_R expt_pos (const cl_R& x, const cl_I& y)
35 return expt(x,y); // x rational -> schnellere Routine
40 while (!oddp(b)) { a = square(a); b = b >> 1; }
45 if (oddp(b)) { c = a * c; }
51 const cl_R expt (const cl_R& x, const cl_I& y)
53 if (eq(y,0)) { return 1; } // y=0 -> Ergebnis 1
54 var bool y_negative = minusp(y);
55 var cl_I abs_y = (y_negative ? -y : y); // Betrag von y nehmen
56 var cl_R z = expt_pos(x,abs_y); // (expt x (abs y))
57 return (y_negative ? recip(z) : z); // evtl. noch Kehrwert nehmen