[][src]Trait const_linear::traits::Real

pub trait Real: Scalar + Ops<Self> {
    fn e() -> Self;
fn sqrt_2() -> Self;
fn pi() -> Self;
fn one_over_pi() -> Self;
fn two_over_pi() -> Self;
fn two_over_sqrt_pi() -> Self;
fn one_over_sqrt_two() -> Self;
fn pi_over_2() -> Self;
fn pi_over_3() -> Self;
fn pi_over_4() -> Self;
fn pi_over_6() -> Self;
fn pi_over_8() -> Self;
fn ln_2() -> Self;
fn ln_10() -> Self;
fn log2_e() -> Self;
fn log10_e() -> Self;
fn approx_eq(self, other: Self, epsilon: Self, max_relative: Self) -> bool; }

A value which is a scalar value and is also capable of representing real numbers. This trait is sealed, and can not be implemented outside of const_linear.

Required methods

fn e() -> Self

Euler's number, e

fn sqrt_2() -> Self

The square root of 2.

fn pi() -> Self

Archimedes' constant, π

fn one_over_pi() -> Self

1 / π

fn two_over_pi() -> Self

2 / π

fn two_over_sqrt_pi() -> Self

2 / √π

fn one_over_sqrt_two() -> Self

1 / √2

fn pi_over_2() -> Self

π / 2

fn pi_over_3() -> Self

π / 3

fn pi_over_4() -> Self

π / 4

fn pi_over_6() -> Self

π / 6

fn pi_over_8() -> Self

π / 8

fn ln_2() -> Self

ln(2)

fn ln_10() -> Self

ln(10)

fn log2_e() -> Self

log2(e)

fn log10_e() -> Self

log(e)

fn approx_eq(self, other: Self, epsilon: Self, max_relative: Self) -> bool

Tests for approximate equality between two real numbers. This is a workaround for the limited precision of floating point numbers.

Examples

use const_linear::traits::Real;

// 0.1 + 0.2 != 0.3 (In floating point arithmetic).
assert_ne!(0.1 + 0.2, 0.3);

// ... But it is *approximately* equal.
assert!((0.1 + 0.2).approx_eq(0.3, std::f64::EPSILON, 1.0E-15))
Loading content...

Implementations on Foreign Types

impl Real for f32[src]

impl Real for f64[src]

Loading content...

Implementors

Loading content...