use crate::gamma::lgamma_rf::lgamma_coref;
pub fn f_lnbetaf(a: f32, b: f32) -> f32 {
let ax = a.to_bits();
let bx = b.to_bits();
if ax >= 0xffu32 << 23 || ax == 0 || bx >= 0xffu32 << 23 || bx == 0 {
if (ax >> 31) != 0 || (bx >> 31) != 0 {
return f32::NAN;
}
if ax.wrapping_shl(1) == 0 || bx.wrapping_shl(1) == 0 {
if ax.wrapping_shl(1) != 0 || bx.wrapping_shl(1) != 0 {
return f32::INFINITY;
}
return f32::NAN;
}
if a.is_infinite() || b.is_infinite() {
return f32::NEG_INFINITY;
}
return a + f32::NAN; }
let (mut y, _) = lgamma_coref(a + b);
let (y1, _) = lgamma_coref(b);
y = y1 - y;
let (y1, _) = lgamma_coref(a);
y += y1;
y as f32
}
pub(crate) fn lnbetaf_core(a: f32, b: f32) -> f64 {
let (mut y, _) = lgamma_coref(a + b);
let (y1, _) = lgamma_coref(b);
y = y1 - y;
let (y1, _) = lgamma_coref(a);
y += y1;
y
}
#[cfg(test)]
mod tests {
use crate::f_lnbetaf;
#[test]
fn test_betaf() {
assert_eq!(f_lnbetaf(1., f32::INFINITY), f32::NEG_INFINITY);
assert_eq!(f_lnbetaf(f32::INFINITY, 0.), f32::INFINITY);
assert!(f_lnbetaf(0., 0.).is_nan());
assert_eq!(f_lnbetaf(0., f32::INFINITY), f32::INFINITY);
assert!(f_lnbetaf(-5., 15.).is_nan());
assert!(f_lnbetaf(5., -15.).is_nan());
assert!(f_lnbetaf(f32::NAN, 15.).is_nan());
assert!(f_lnbetaf(15., f32::NAN).is_nan());
assert_eq!(f_lnbetaf(f32::INFINITY, 1.), f32::NEG_INFINITY);
assert_eq!(f_lnbetaf(5., 3.), -4.65396);
assert_eq!(f_lnbetaf(3., 5.), -4.65396);
assert_eq!(f_lnbetaf(12., 23.), -22.607338);
}
}