use num_traits::Float;
use strafe_type::{FloatConstraint, LogProbability64, Probability64, Rational64, Real64};
use crate::traits::DPQ;
pub fn qweibull<P: Into<Probability64>, RA1: Into<Rational64>, RA2: Into<Rational64>>(
p: P,
shape: RA1,
scale: RA2,
lower_tail: bool,
) -> Real64 {
let p = p.into().unwrap();
qweibull_inner(p, shape, scale, lower_tail, false)
}
pub fn log_qweibull<LP: Into<LogProbability64>, RA1: Into<Rational64>, RA2: Into<Rational64>>(
p: LP,
shape: RA1,
scale: RA2,
lower_tail: bool,
) -> Real64 {
let p = p.into().unwrap();
qweibull_inner(p, shape, scale, lower_tail, true)
}
pub fn qweibull_inner<R1: Into<Rational64>, R2: Into<Rational64>>(
p: f64,
shape: R1,
scale: R2,
lower_tail: bool,
log: bool,
) -> Real64 {
let shape = shape.into().unwrap();
let scale = scale.into().unwrap();
if let Some(ret) = p.q_p01_boundaries(0.0, f64::infinity(), lower_tail, log) {
return ret.into();
}
(scale * (-p.dt_clog(lower_tail, log)).powf(1.0 / shape)).into()
}