#[cfg(test)]
use super::assert_f64_roughly_eq;
pub fn h_5(t: f64, n: usize) -> f64 {
let t2 = t.powi(2);
let t3 = t.powi(3);
let t4 = t.powi(4);
let t5 = t.powi(5);
match n {
0 => t5.mul_add(-6., t4.mul_add(15., t3.mul_add(-10., 1.))),
1 => t5.mul_add(-3., t4.mul_add(8., t3.mul_add(-6., t))),
2 => t5.mul_add(-0.5, t4.mul_add(1.5, t3.mul_add(-1.5, t2 * 0.5))),
3 => t5.mul_add(0.5, t4.mul_add(-1., t3 * 0.5)),
4 => t5.mul_add(-3., t4.mul_add(7., t3 * -4.)),
5 => t5.mul_add(6., t4.mul_add(-15., t3 * 10.)),
_ => unimplemented!(),
}
}
pub fn h_5p(t: f64, n: usize) -> f64 {
let t2 = t.powi(2);
let t3 = t.powi(3);
let t4 = t.powi(4);
match n {
0 => t4.mul_add(-30., t3.mul_add(60., t2 * -30.)),
1 => t4.mul_add(-15., t3.mul_add(32., t2.mul_add(-18., 1.))),
2 => t4.mul_add(-2.5, t3.mul_add(6., t2.mul_add(-4.5, t))),
3 => t4.mul_add(2.5, t3.mul_add(-4., t2 * 1.5)),
4 => t4.mul_add(-15., t3.mul_add(28., t2 * -12.)),
5 => t4.mul_add(30., t3.mul_add(-60., t2 * 30.)),
_ => unimplemented!(),
}
}
pub fn h_5pp(t: f64, n: usize) -> f64 {
let t2 = t.powi(2);
let t3 = t.powi(3);
match n {
0 => t3.mul_add(-120., t2.mul_add(180., t * -60.)),
1 => t3.mul_add(-60., t2.mul_add(96., t * -36.)),
2 => t3.mul_add(-10., t2.mul_add(18., t.mul_add(-9., 1.))),
3 => t3.mul_add(10., t2.mul_add(-12., t * 3.)),
4 => t3.mul_add(-60., t2.mul_add(84., t * -24.)),
5 => t3.mul_add(120., t2.mul_add(-180., t * 60.)),
_ => unimplemented!(),
}
}
#[test]
fn h_5_is_correct() {
assert_f64_roughly_eq!(h_5(0.0, 0), 1.);
assert_f64_roughly_eq!(h_5(0.0, 0), 1.);
assert_f64_roughly_eq!(h_5(0.0, 1), 0.);
assert_f64_roughly_eq!(h_5(0.0, 2), 0.);
assert_f64_roughly_eq!(h_5(0.0, 3), 0.);
assert_f64_roughly_eq!(h_5(0.0, 4), 0.);
assert_f64_roughly_eq!(h_5(0.0, 5), 0.);
assert_f64_roughly_eq!(h_5(1.0, 0), 0.);
assert_f64_roughly_eq!(h_5(1.0, 1), 0.);
assert_f64_roughly_eq!(h_5(1.0, 2), 0.);
assert_f64_roughly_eq!(h_5(1.0, 3), 0.);
assert_f64_roughly_eq!(h_5(1.0, 4), 0.);
assert_f64_roughly_eq!(h_5(1.0, 5), 1.);
}
#[test]
fn h_5p_is_correct() {
assert_f64_roughly_eq!(h_5p(0.0, 0), 0.);
assert_f64_roughly_eq!(h_5p(0.0, 1), 1.);
assert_f64_roughly_eq!(h_5p(0.0, 2), 0.);
assert_f64_roughly_eq!(h_5p(0.0, 3), 0.);
assert_f64_roughly_eq!(h_5p(0.0, 4), 0.);
assert_f64_roughly_eq!(h_5p(0.0, 5), 0.);
assert_f64_roughly_eq!(h_5p(1.0, 0), 0.);
assert_f64_roughly_eq!(h_5p(1.0, 1), 0.);
assert_f64_roughly_eq!(h_5p(1.0, 2), 0.);
assert_f64_roughly_eq!(h_5p(1.0, 3), 0.);
assert_f64_roughly_eq!(h_5p(1.0, 4), 1.);
assert_f64_roughly_eq!(h_5p(1.0, 5), 0.);
}
#[test]
fn h_5pp_is_correct() {
assert_f64_roughly_eq!(h_5pp(0.0, 0), 0.);
assert_f64_roughly_eq!(h_5pp(0.0, 1), 0.);
assert_f64_roughly_eq!(h_5pp(0.0, 2), 1.);
assert_f64_roughly_eq!(h_5pp(0.0, 3), 0.);
assert_f64_roughly_eq!(h_5pp(0.0, 4), 0.);
assert_f64_roughly_eq!(h_5pp(0.0, 5), 0.);
assert_f64_roughly_eq!(h_5pp(1.0, 0), 0.);
assert_f64_roughly_eq!(h_5pp(1.0, 1), 0.);
assert_f64_roughly_eq!(h_5pp(1.0, 2), 0.);
assert_f64_roughly_eq!(h_5pp(1.0, 3), 1.);
assert_f64_roughly_eq!(h_5pp(1.0, 4), 0.);
assert_f64_roughly_eq!(h_5pp(1.0, 5), 0.);
}