use anyhow::{anyhow, Result};
use num::{Float, ToPrimitive};
use std::fmt::Debug;
#[allow(clippy::inline_always)]
#[inline(always)]
pub fn cast<X, F>(x: X) -> Result<F>
where
X: ToPrimitive,
F: Float + Debug,
{
F::from(x).ok_or_else(|| anyhow!("Couldn't cast a value to a floating-point number"))
}