[][src]Struct log_domain::LogDomain

pub struct LogDomain<F: Float>(_);

A struct that represents positive floats by their natural logarithm.

Examples

use log_domain::LogDomain;
use num_traits::{One, Zero};

match (LogDomain::new(0.5), LogDomain::new(0.25), LogDomain::new(0.75)) {
    (Ok(x), Ok(y), Ok(z)) => {
        assert_eq!(x.value(), 0.5);            // 0.5         = 0.5
        assert_eq!(x.ln(), f64::ln(0.5));      // ln(0.5)     = ln(0.5)

        // Operations `+`, `-`, `*`, `/`, and `pow`
        assert_eq!(x + y, z);                  // 0.5  + 0.25 = 0.75
        assert_eq!(z - x, y);                  // 0.75 - 0.5  = 0.25
        assert_eq!(x * x, y);                  // 0.5  ⋅ 0.5  = 0.25
        assert_eq!(y / x, x);                  // 0.25 / 0.5  = 0.5
        assert_eq!(x.pow(2.0), y);             // 0.5²        = 0.25
        assert_eq!(y.pow(1.0 / 2.0), x);       // √0.25       = 0.5

        // Assignment operators `+=`, `-=`, `*=`, and `/=`
        let mut a = x;
        a += y;                                // a = 0.5  + 0.25 = 0.75
        assert_eq!(a, z);                      // a = 0.75 = z
        a = z;
        a -= x;                                // a = 0.75 - 0.5  = 0.25
        assert_eq!(a, y);                      // a = 0.25 = y
        a = x;
        a *= a;                                // a = 0.5  * 0.5  = 0.25
        assert_eq!(a, y);                      // a = 0.25 = y
        a = y;
        a /= x;                                // a = 0.25 / 0.5  = 0.5
        assert_eq!(a, x);                      // a = 0.5 = x

        // Neutral elements `LogDomain::zero()` and `LogDomain::one()`
        assert_eq!(z + LogDomain::zero(), z);  // 0.75 + 0    = 0.75
        assert_eq!(z - z, LogDomain::zero());  // 0.75 - 0.75 = 0
        assert_eq!(z * LogDomain::one(), z);   // 0.75 * 1    = 0.75
        assert_eq!(z / z, LogDomain::one());   // 0.75 / 0.75 = 1
        assert_eq!(z * LogDomain::zero(), LogDomain::zero());
                                               // 0.75 * 0    = 0
        assert_eq!(z.pow(0.0), LogDomain::one());
                                               // 0.75⁰       = 1

        // Comparison
        assert!(z > y);                        // 0.75 > 0.25
        assert!(y < z);                        // 0.25 < 0.75
    },
    _ => panic!(),
}

Methods

impl<F: Float + Debug> LogDomain<F>[src]

pub fn new(value: F) -> Result<Self, String>[src]

Creates a new LogDomain from a given value in the interval [0,∞).

impl<F: Float> LogDomain<F>[src]

pub fn ln(&self) -> F[src]

Logarithm of the value that is represented by the given LogDomain.

pub fn value(&self) -> F[src]

Value that is represented by the given LogDomain.

pub fn pow(&self, power: F) -> Self[src]

Raise the represented probability to the power of a Float value.

Trait Implementations

impl<F: Float> Eq for LogDomain<F>[src]

impl<F: Float> Ord for LogDomain<F>[src]

An impl of Ord that defines Exp(NaN) = Exp(NaN), Exp(NaN) < Exp(y), and Exp(x) < Exp(y) for x < y.

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

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

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<F: Float> PartialEq<LogDomain<F>> for LogDomain<F>[src]

An impl of PartialEq that defines Exp(NaN) = Exp(NaN) and Exp(x) = Exp(y) for x - y < F::EPSILON.

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<F: Copy + Float> Copy for LogDomain<F>[src]

impl<F: Clone + Float> Clone for LogDomain<F>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<F: PartialOrd + Float> PartialOrd<LogDomain<F>> for LogDomain<F>[src]

impl<F: Debug + Float> Debug for LogDomain<F>[src]

impl<F: Float + Display> Display for LogDomain<F>[src]

impl<F: Float + Debug> Sub<LogDomain<F>> for LogDomain<F>[src]

An impl of Sub that uses only two applications of transcendental functions (exp_m1 and ln) to increase precision.

type Output = Self

The resulting type after applying the - operator.

impl<F: Float> Add<LogDomain<F>> for LogDomain<F>[src]

An impl of Add that uses only two applications of transcendental functions (exp and ln_1p) to increase precision.

type Output = Self

The resulting type after applying the + operator.

impl<F: Float> Mul<LogDomain<F>> for LogDomain<F>[src]

type Output = Self

The resulting type after applying the * operator.

impl<F: Float> Div<LogDomain<F>> for LogDomain<F>[src]

type Output = Self

The resulting type after applying the / operator.

impl<F: Float> AddAssign<LogDomain<F>> for LogDomain<F>[src]

impl<F: Float + Debug> SubAssign<LogDomain<F>> for LogDomain<F>[src]

impl<F: Float> MulAssign<LogDomain<F>> for LogDomain<F>[src]

impl<F: Float> DivAssign<LogDomain<F>> for LogDomain<F>[src]

impl<F: Debug + Float + FromStr<Err = E>, E: ToString> FromStr for LogDomain<F>[src]

type Err = String

The associated error which can be returned from parsing.

impl<F: Float> One for LogDomain<F>[src]

fn set_one(&mut self)[src]

Sets self to the multiplicative identity element of Self, 1.

fn is_one(&self) -> bool where
    Self: PartialEq<Self>, 
[src]

Returns true if self is equal to the multiplicative identity. Read more

impl<F: Float> Zero for LogDomain<F>[src]

fn set_zero(&mut self)[src]

Sets self to the additive identity element of Self, 0.

impl<F: Float + Serialize> Serialize for LogDomain<F>[src]

impl<'de, F: Float + Deserialize<'de>> Deserialize<'de> for LogDomain<F>[src]

Auto Trait Implementations

impl<F> Send for LogDomain<F> where
    F: Send

impl<F> Sync for LogDomain<F> where
    F: Sync

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]