/* sin(PI*x) assuming x > 2^-100, if sin(PI*x)==0 the sign is arbitrary */ fn sin_pi(mut x: f32) -> f32 { letmut y: f64; letmut n: isize;
/* spurious inexact if odd int */
x = 2.0 * (x * 0.5 - floorf(x * 0.5)); /* x mod 2.0 */
n = (x * 4.0) as isize;
n = div!(n + 1, 2);
y = (x as f64) - (n as f64) * 0.5;
y *= 3.14159265358979323846; match n { 1 => k_cosf(y), 2 => k_sinf(-y), 3 => -k_cosf(y), 0 | _ => k_sinf(y),
}
}
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pubfn lgammaf_r(mut x: f32) -> (f32, i32) { let u = x.to_bits(); letmut t: f32; let y: f32; letmut z: f32; let nadj: f32; let p: f32; let p1: f32; let p2: f32; let p3: f32; let q: f32; letmut r: f32; let w: f32; let ix: u32; let i: i32; let sign: bool; letmut signgam: i32;
/* purge off +-inf, NaN, +-0, tiny and negative arguments */
signgam = 1;
sign = (u >> 31) != 0;
ix = u & 0x7fffffff; if ix >= 0x7f800000 { return (x * x, signgam);
} if ix < 0x35000000 { /* |x| < 2**-21, return -log(|x|) */ if sign {
signgam = -1;
x = -x;
} return (-logf(x), signgam);
} if sign {
x = -x;
t = sin_pi(x); if t == 0.0 { /* -integer */ return (1.0 / (x - x), signgam);
} if t > 0.0 {
signgam = -1;
} else {
t = -t;
}
nadj = logf(PI / (t * x));
} else {
nadj = 0.0;
}
/* purge off 1 and 2 */ if ix == 0x3f800000 || ix == 0x40000000 {
r = 0.0;
} /* for x < 2.0 */ elseif ix < 0x40000000 { if ix <= 0x3f666666 { /* lgamma(x) = lgamma(x+1)-log(x) */
r = -logf(x); if ix >= 0x3f3b4a20 {
y = 1.0 - x;
i = 0;
} elseif ix >= 0x3e6d3308 {
y = x - (TC - 1.0);
i = 1;
} else {
y = x;
i = 2;
}
} else {
r = 0.0; if ix >= 0x3fdda618 { /* [1.7316,2] */
y = 2.0 - x;
i = 0;
} elseif ix >= 0x3F9da620 { /* [1.23,1.73] */
y = x - TC;
i = 1;
} else {
y = x - 1.0;
i = 2;
}
} match i { 0 => {
z = y * y;
p1 = A0 + z * (A2 + z * (A4 + z * (A6 + z * (A8 + z * A10))));
p2 = z * (A1 + z * (A3 + z * (A5 + z * (A7 + z * (A9 + z * A11)))));
p = y * p1 + p2;
r += p - 0.5 * y;
} 1 => {
z = y * y;
w = z * y;
p1 = T0 + w * (T3 + w * (T6 + w * (T9 + w * T12))); /* parallel comp */
p2 = T1 + w * (T4 + w * (T7 + w * (T10 + w * T13)));
p3 = T2 + w * (T5 + w * (T8 + w * (T11 + w * T14)));
p = z * p1 - (TT - w * (p2 + y * p3));
r += TF + p;
} 2 => {
p1 = y * (U0 + y * (U1 + y * (U2 + y * (U3 + y * (U4 + y * U5)))));
p2 = 1.0 + y * (V1 + y * (V2 + y * (V3 + y * (V4 + y * V5))));
r += -0.5 * y + p1 / p2;
} #[cfg(debug_assertions)]
_ => unreachable!(), #[cfg(not(debug_assertions))]
_ => {}
}
} elseif ix < 0x41000000 { /* x < 8.0 */
i = x as i32;
y = x - (i as f32);
p = y * (S0 + y * (S1 + y * (S2 + y * (S3 + y * (S4 + y * (S5 + y * S6))))));
q = 1.0 + y * (R1 + y * (R2 + y * (R3 + y * (R4 + y * (R5 + y * R6)))));
r = 0.5 * y + p / q;
z = 1.0; /* lgamma(1+s) = log(s) + lgamma(s) */ // TODO: In C, this was implemented using switch jumps with fallthrough. // Does this implementation have performance problems? if i >= 7 {
z *= y + 6.0;
} if i >= 6 {
z *= y + 5.0;
} if i >= 5 {
z *= y + 4.0;
} if i >= 4 {
z *= y + 3.0;
} if i >= 3 {
z *= y + 2.0;
r += logf(z);
}
} elseif ix < 0x5c800000 { /* 8.0 <= x < 2**58 */
t = logf(x);
z = 1.0 / x;
y = z * z;
w = W0 + z * (W1 + y * (W2 + y * (W3 + y * (W4 + y * (W5 + y * W6)))));
r = (x - 0.5) * (t - 1.0) + w;
} else { /* 2**58 <= x <= inf */
r = x * (logf(x) - 1.0);
} if sign {
r = nadj - r;
} return (r, signgam);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.