Skip to main content

FloatExt

Trait FloatExt 

Source
pub trait FloatExt {
    // Required methods
    fn ln(self) -> Self;
    fn sqrt(self) -> Self;
    fn cos(self) -> Self;
    fn exp(self) -> Self;
}
Expand description

Floating-point math operations bridged across std / libm.

This trait provides a unified interface for mathematical functions that are usually available in the standard library but missing in core.

§Examples

use vrd::FloatExt;

let n = 2.0f64;
let ln_n = n.ln();
let sqrt_n = n.sqrt();

Required Methods§

Source

fn ln(self) -> Self

Natural logarithm.

§Examples
use vrd::FloatExt;
let n: f64 = std::f64::consts::E;
assert!((FloatExt::ln(n) - 1.0).abs() < 1e-12);
Source

fn sqrt(self) -> Self

Square root.

§Examples
use vrd::FloatExt;
assert!((FloatExt::sqrt(4.0_f64) - 2.0).abs() < 1e-12);
Source

fn cos(self) -> Self

Cosine.

§Examples
use vrd::FloatExt;
assert!(FloatExt::cos(0.0_f64) - 1.0 < 1e-12);
Source

fn exp(self) -> Self

Exponential.

§Examples
use vrd::FloatExt;
assert!((FloatExt::exp(0.0_f64) - 1.0).abs() < 1e-12);

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 FloatExt for f64

Available on crate feature std only.
Source§

fn ln(self) -> Self

Source§

fn sqrt(self) -> Self

Source§

fn cos(self) -> Self

Source§

fn exp(self) -> Self

Implementors§