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]
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]
fn ln(&self) -> F
[src]
Logarithm of the value that is represented by the given LogDomain
.
fn value(&self) -> F
[src]
Value that is represented by the given LogDomain
.
fn pow(&self, power: F) -> Self
[src]
Raise the represented probability to the power of a Float
value.
Trait Implementations
impl<F: PartialOrd + Float> PartialOrd for LogDomain<F>
[src]
fn partial_cmp(&self, __arg_0: &LogDomain<F>) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &LogDomain<F>) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &LogDomain<F>) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &LogDomain<F>) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &LogDomain<F>) -> bool
[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]
impl<F: Clone + Float> Clone for LogDomain<F>
[src]
fn clone(&self) -> LogDomain<F>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
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
.
fn cmp(&self, other: &Self) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
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
.
fn eq(&self, other: &Self) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
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.
type Output = Self
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self
[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.
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, other: Self) -> Self
[src]
Performs the -
operation.
impl<F: Float> Mul for LogDomain<F>
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self
[src]
Performs the *
operation.
impl<F: Float> Div for LogDomain<F>
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, other: Self) -> Self
[src]
Performs the /
operation.
impl<F: Float> Zero for LogDomain<F>
[src]
fn zero() -> Self
[src]
Returns the additive identity element of Self
, 0
. Read more
fn is_zero(&self) -> bool
[src]
Returns true
if self
is equal to the additive identity.
impl<F: Float> One 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.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
Parses a string s
to return a value of this type. Read more