pub trait Float:
Sealed
+ Copy
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self> {
// Required methods
fn from_f32(v: f32) -> Self;
fn from_f64(v: f64) -> Self;
fn to_f32(self) -> f32;
fn to_f64(self) -> f64;
fn exp(self) -> Self;
fn log10(self) -> Self;
fn powf(self, exp: Self) -> Self;
}Expand description
Broad numeric trait for code that operates on f32 or f64 but
isn’t necessarily handling audio samples. Use this for math
utilities (gain conversions, frequency math, filter coefficients).
For audio-sample-typed surfaces (AudioBuffer<S>, smoother
reads), use Sample instead, which extends Float with the
marker bounds buffer code needs.
Required Methods§
Sourcefn from_f32(v: f32) -> Self
fn from_f32(v: f32) -> Self
Widen an f32 to this precision. Lossless for f64; identity
for f32.
Sourcefn from_f64(v: f64) -> Self
fn from_f64(v: f64) -> Self
Narrow an f64 to this precision. Identity for f64. For
f32, debug-asserts non-NaN - DSP code that produces a NaN
here is always a bug, and silent NaN propagation through the
audio path causes host-inconsistent behaviour. Release builds
preserve NaN via the bare as cast so the upstream bug stays
visible.
Sourcefn to_f32(self) -> f32
fn to_f32(self) -> f32
Narrow to f32. Identity for f32; for f64, same NaN
debug-assert as Self::from_f64.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".