Skip to main content

Float

Trait Float 

Source
pub trait Float:
    Copy
    + 'static
    + PartialOrd
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Div<Output = Self>
    + Neg<Output = Self> {
    const ZERO: Self;
    const ONE: Self;
    const MIN_POSITIVE: Self;
Show 16 methods // Required methods fn from_f64(v: f64) -> Self; fn powf(self, exp: Self) -> Self; fn cbrt(self) -> Self; fn sqrt(self) -> Self; fn ln(self) -> Self; fn exp(self) -> Self; fn sin(self) -> Self; fn cos(self) -> Self; fn atan2(self, x: Self) -> Self; fn round(self) -> Self; fn powi(self, n: i32) -> Self; fn abs(self) -> Self; fn rem_euclid(self, rhs: Self) -> Self; fn clamp(self, min: Self, max: Self) -> Self; fn max(self, other: Self) -> Self; fn min(self, other: Self) -> Self;
}
Expand description

Floating-point scalar operations for color math.

Implemented for f32 and f64. When f16 stabilizes in Rust it will implement this trait and all operations will work at half precision without further changes. Transcendental functions are provided by the standard library under the std feature and by libm under no_std.

Required Associated Constants§

Source

const ZERO: Self

Additive identity.

Source

const ONE: Self

Multiplicative identity.

Source

const MIN_POSITIVE: Self

Smallest positive value.

Required Methods§

Source

fn from_f64(v: f64) -> Self

Convert an f64 literal to Self. Used to widen f32 constants in generic code; for f32 this narrows back from f64, which is lossless for all constants in this crate.

Source

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

base^exp.

Source

fn cbrt(self) -> Self

Cube root.

Source

fn sqrt(self) -> Self

Square root.

Source

fn ln(self) -> Self

Natural logarithm.

Source

fn exp(self) -> Self

Natural exponential.

Source

fn sin(self) -> Self

Sine (radians).

Source

fn cos(self) -> Self

Cosine (radians).

Source

fn atan2(self, x: Self) -> Self

atan2(self, x).

Source

fn round(self) -> Self

Round to nearest integer.

Source

fn powi(self, n: i32) -> Self

Integer power.

Source

fn abs(self) -> Self

Absolute value.

Source

fn rem_euclid(self, rhs: Self) -> Self

Euclidean remainder.

Source

fn clamp(self, min: Self, max: Self) -> Self

Clamp to [min, max].

Source

fn max(self, other: Self) -> Self

Greater of self and other.

Source

fn min(self, other: Self) -> Self

Lesser of self and other.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Float for f32

Source§

const ZERO: f32 = 0.0

Source§

const ONE: f32 = 1.0

Source§

const MIN_POSITIVE: f32 = f32::MIN_POSITIVE

Source§

fn from_f64(v: f64) -> f32

Source§

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

Source§

fn cbrt(self) -> f32

Source§

fn sqrt(self) -> f32

Source§

fn ln(self) -> f32

Source§

fn exp(self) -> f32

Source§

fn sin(self) -> f32

Source§

fn cos(self) -> f32

Source§

fn atan2(self, x: f32) -> f32

Source§

fn round(self) -> f32

Source§

fn powi(self, n: i32) -> f32

Source§

fn abs(self) -> f32

Source§

fn rem_euclid(self, rhs: f32) -> f32

Source§

fn clamp(self, min: f32, max: f32) -> f32

Source§

fn max(self, other: f32) -> f32

Source§

fn min(self, other: f32) -> f32

Source§

impl Float for f64

Source§

const ZERO: f64 = 0.0

Source§

const ONE: f64 = 1.0

Source§

const MIN_POSITIVE: f64 = f64::MIN_POSITIVE

Source§

fn from_f64(v: f64) -> f64

Source§

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

Source§

fn cbrt(self) -> f64

Source§

fn sqrt(self) -> f64

Source§

fn ln(self) -> f64

Source§

fn exp(self) -> f64

Source§

fn sin(self) -> f64

Source§

fn cos(self) -> f64

Source§

fn atan2(self, x: f64) -> f64

Source§

fn round(self) -> f64

Source§

fn powi(self, n: i32) -> f64

Source§

fn abs(self) -> f64

Source§

fn rem_euclid(self, rhs: f64) -> f64

Source§

fn clamp(self, min: f64, max: f64) -> f64

Source§

fn max(self, other: f64) -> f64

Source§

fn min(self, other: f64) -> f64

Implementors§