4 #include "base/cl_sysdep.h"
12 #include "real/cl_R.h"
13 #include "cln/rational.h"
14 #include "cln/integer.h"
21 // Solange b gerade, setze a:=a*a, b:=b/2. [a^b bleibt invariant, = x^y.]
23 // Solange b:=floor(b/2) >0 ist,
24 // setze a:=a*a, und falls b ungerade, setze c:=a*c.
26 // Für y=0: Ergebnis 1.
27 // Für y<0: (/ (expt x (- y))).
30 inline const cl_R expt_pos (const cl_R& x, uintL y)
34 return expt(x,y); // x rational -> schnellere Routine
39 while (!(b % 2)) { a = square(a); b = b >> 1; }
44 if (b % 2) { c = a * c; }
50 const cl_R expt (const cl_R& x, sintL y)
52 if (y==0) { return 1; } // y=0 -> Ergebnis 1
53 var uintL abs_y = (y<0 ? (uintL)(-y) : y); // Betrag von y nehmen
54 var cl_R z = expt_pos(x,abs_y); // (expt x (abs y))
55 return (y<0 ? recip(z) : z); // evtl. noch Kehrwert nehmen