Struct log_domain::LogDomain [] [src]

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

        // 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]

[src]

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

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

[src]

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

[src]

Value that is represented by the given LogDomain.

[src]

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

Trait Implementations

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

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

[src]

Formats the value using the given formatter.

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

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<F: Copy + Float> Copy 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.

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

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

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

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

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

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the * operator.

[src]

Performs the * operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

[src]

Returns the additive identity element of Self, 0. Read more

[src]

Returns true if self is equal to the additive identity.

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

[src]

Returns the multiplicative identity element of Self, 1. Read more

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

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

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

[src]

Formats the value using the given formatter. Read more