// berechne rekursiv z:=(sin(y)/y)^2 und liefere z*(1-y^2*z).
// [Die Grenze sqrt(d) ergibt sich so:
// Man braucht bei der Potenzreihe mit x=2^-k etwa j Glieder, mit
-// k*j*ln 2 + j*(ln j - 1) = d, und der Aufwand beträgt etwa 2.8*(j/2)
+// k*j*ln 2 + j*(ln j - 1) = d, und der Aufwand beträgt etwa 2.8*(j/2)
// Multiplikationen von d-Bit-Zahlen. Bei Halbierungen bis x=2^-k ist der
// Gesamtaufwand etwa 2*(k+e)+1.4*j(k). Dieses minimieren nach k: Soll sein
// -1.4 = d/dk j(k) = (d/dj k(j))^-1 = - j^2/(d+j)*ln 2, also j^2=2(d+j),
if (zerop(x))
return cl_float(1,x);
- var uintL d = float_digits(x);
- var sintL e = float_exponent(x);
- if (e <= (-(sintL)d)>>1) // e <= (-d)/2 <==> e <= -ceiling(d/2) ?
+ var uintC d = float_digits(x);
+ var sintE e = float_exponent(x);
+ if (e <= (-(sintC)d)>>1) // e <= (-d)/2 <==> e <= -ceiling(d/2) ?
return cl_float(1,x); // ja -> 1.0 als Ergebnis
{ Mutable(cl_F,x);
// Bei e <= -1-limit_slope*floor(sqrt(d)) kann die Potenzreihe
// 50 0.35-0.40
// 100 0.40-0.45
// 200 0.40-0.45
- // Wähle limit_slope = 13/32 = 0.4.
- var sintL e_limit = -1-floor(isqrt(d)*13,32); // -1-floor(sqrt(d))
+ // Wähle limit_slope = 13/32 = 0.4.
+ var sintL e_limit = -1-floor(isqrtC(d)*13,32); // -1-floor(sqrt(d))
if (e > e_limit) {
- // e > -1-limit_slope*floor(sqrt(d)) -> muß |x| verkleinern.
+ // e > -1-limit_slope*floor(sqrt(d)) -> muß |x| verkleinern.
x = scale_float(x,e_limit-e);
// Neuer Exponent = e_limit.
}
while (e > e_limit) {
z = z - x2 * square(z);
x2 = scale_float(x2,2); // x^2 := x^2*4
- e_limit++;
+ e--;
}
return z;
}}
// berechne rekursiv z:=sin(y)^2 und liefere 4*z*(1-z) = 1-(1-2*z)^2.
// [Die Grenze sqrt(d) ergibt sich so:
// Man braucht bei der Potenzreihe mit x=2^-k etwa j Glieder, mit
-// k*j*ln 2 + j*(ln j - 1) = d, und der Aufwand beträgt etwa 2.8*(j/2)
+// k*j*ln 2 + j*(ln j - 1) = d, und der Aufwand beträgt etwa 2.8*(j/2)
// Multiplikationen von d-Bit-Zahlen. Bei Halbierungen bis x=2^-k ist der
// Gesamtaufwand etwa 2*(k+e)+1.4*j(k). Dieses minimieren nach k: Soll sein
// -1.4 = d/dk j(k) = (d/dj k(j))^-1 = - j^2/(d+j)*ln 2, also j^2=2(d+j),
if (zerop(x))
return x;
- var uintL actuallen = TheLfloat(x)->len;
- var uintL d = float_digits(x);
- var sintL e = float_exponent(x);
- if (e <= (-(sintL)d)>>1) // e <= (-d)/2 <==> e <= -ceiling(d/2) ?
+ var uintC actuallen = TheLfloat(x)->len;
+ var uintC d = float_digits(x);
+ var sintE e = float_exponent(x);
+ if (e <= (-(sintC)d)>>1) // e <= (-d)/2 <==> e <= -ceiling(d/2) ?
return square(x); // ja -> x^2 als Ergebnis
{ Mutable(cl_LF,x);
- var sintL ee = e;
+ var sintE ee = e;
// Bei e <= -1-limit_slope*floor(sqrt(d)) kann die Potenzreihe
// angewandt werden. limit_slope = 1.0 ist schlecht (ca. 10% zu
- // schlecht). Ein guter Wert für naive1 ist limit_slope = 0.6,
- // für naive3 aber limit_slope = 0.5.
- var sintL e_limit = -1-floor(isqrt(d),2); // -1-floor(sqrt(d))
+ // schlecht). Ein guter Wert für naive1 ist limit_slope = 0.6,
+ // für naive3 aber limit_slope = 0.5.
+ var sintL e_limit = -1-floor(isqrtC(d),2); // -1-floor(sqrt(d))
if (e > e_limit) {
- // e > -1-limit_slope*floor(sqrt(d)) -> muß |x| verkleinern.
+ // e > -1-limit_slope*floor(sqrt(d)) -> muß |x| verkleinern.
x = scale_float(x,e_limit-e);
ee = e_limit; // Neuer Exponent = e_limit.
}
b = round1(round1(The(cl_LF)(b*a)),(cl_I)((i+1)*(i+2)));
i = i+2;
}
- powser_value = scale_float(cl_float(sum,x),-d);
+ powser_value = scale_float(cl_float(sum,x),-(sintC)d);
} else if (actuallen <= 7) { // Break-even-Point before extendsqrt: N<=6
// naive2:
// floating-point representation
// naive3:
// floating-point representation with smooth precision reduction
var cl_LF b = x; // b := x
- var cl_LF eps = scale_float(b,-(sintL)d-10);
+ var cl_LF eps = scale_float(b,-(sintC)d-10);
var cl_LF sum = cl_float(0,x); // sum := (float 0 x)
loop {
var cl_LF new_sum = sum + LF_to_LF(b,actuallen);
var cl_LF z = square(powser_value); // sin^2 als Ergebnis
while (e > e_limit) {
z = cl_float(1,x) - square(cl_float(1,x) - scale_float(z,1)); // z := 1-(1-2*z)^2
- e_limit++;
+ e--;
}
return z;
}}