Skip to main content

Float

Trait Float 

Source
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§

Source

fn from_f32(v: f32) -> Self

Widen an f32 to this precision. Lossless for f64; identity for f32.

Source

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.

Source

fn to_f32(self) -> f32

Narrow to f32. Identity for f32; for f64, same NaN debug-assert as Self::from_f64.

Source

fn to_f64(self) -> f64

Widen to f64. Identity for f64; lossless for f32.

Source

fn exp(self) -> Self

Natural exponential. Forwards to the type’s intrinsic.

Source

fn log10(self) -> Self

Base-10 logarithm. Forwards to the type’s intrinsic.

Source

fn powf(self, exp: Self) -> Self

self.powf(exp). Forwards to the type’s intrinsic.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Float for f32

Source§

fn from_f32(v: f32) -> f32

Source§

fn from_f64(v: f64) -> f32

Source§

fn to_f32(self) -> f32

Source§

fn to_f64(self) -> f64

Source§

fn exp(self) -> f32

Source§

fn log10(self) -> f32

Source§

fn powf(self, exp: f32) -> f32

Source§

impl Float for f64

Source§

fn from_f32(v: f32) -> f64

Source§

fn from_f64(v: f64) -> f64

Source§

fn to_f32(self) -> f32

Source§

fn to_f64(self) -> f64

Source§

fn exp(self) -> f64

Source§

fn log10(self) -> f64

Source§

fn powf(self, exp: f64) -> f64

Implementors§