pub trait Sample: Copy + Send + Sync + 'static + private::Sealed {
const ZERO: Self;
const IS_F64: bool;
fn from_f32(value: f32) -> Self;
fn to_f32(self) -> f32;
}
impl Sample for f32 {
const ZERO: Self = 0.0;
const IS_F64: bool = false;
#[inline]
fn from_f32(value: f32) -> Self {
value
}
#[inline]
fn to_f32(self) -> f32 {
self
}
}
impl Sample for f64 {
const ZERO: Self = 0.0;
const IS_F64: bool = true;
#[inline]
fn from_f32(value: f32) -> Self {
f64::from(value)
}
#[inline]
#[allow(clippy::cast_possible_truncation)]
fn to_f32(self) -> f32 {
self as f32
}
}
mod private {
pub trait Sealed {}
impl Sealed for f32 {}
impl Sealed for f64 {}
}