use num::{Float, FromPrimitive};
use std::f64::consts::PI;
pub fn holder_table<T: Float + FromPrimitive>(param: &[T]) -> T {
assert!(param.len() == 2);
let (x1, x2) = (param[0], param[1]);
let pi = T::from_f64(PI).unwrap();
-(x1.sin() * x2.cos()
* (T::from_f64(1.0).unwrap() - (x1.powi(2) + x2.powi(2)).sqrt() / pi)
.abs()
.exp())
.abs()
}
mod tests {
#[test]
fn test_holder_table_optimum() {
assert!(
(::holder_table(&[8.05502_f32, 9.66459_f32]) + 19.2085).abs() < ::std::f32::EPSILON
);
assert!(
(::holder_table(&[8.05502_f32, 9.66459_f32]) + 19.2085).abs() < ::std::f32::EPSILON
);
assert!(
(::holder_table(&[8.05502_f32, 9.66459_f32]) + 19.2085).abs() < ::std::f32::EPSILON
);
assert!(
(::holder_table(&[8.05502_f32, 9.66459_f32]) + 19.2085).abs() < ::std::f32::EPSILON
);
}
#[test]
#[should_panic]
fn test_holder_table_param_length() {
::holder_table(&[0.0_f32, -1.0_f32, 0.1_f32]);
}
}