[−][src]Struct log_domain::LogDomain
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 cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
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
.
fn eq(&self, other: &Self) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<F: Clone + Float> Clone for LogDomain<F>
[src]
fn clone(&self) -> 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]
fn partial_cmp(&self, other: &LogDomain<F>) -> Option<Ordering>
[src]
fn lt(&self, other: &LogDomain<F>) -> bool
[src]
fn le(&self, other: &LogDomain<F>) -> bool
[src]
fn gt(&self, other: &LogDomain<F>) -> bool
[src]
fn ge(&self, other: &LogDomain<F>) -> bool
[src]
impl<F: Copy + Float> Copy 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.
fn sub(self, other: Self) -> Self
[src]
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.
fn add(self, other: Self) -> Self
[src]
impl<F: Float> Mul<LogDomain<F>> for LogDomain<F>
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self
[src]
impl<F: Float> Div<LogDomain<F>> for LogDomain<F>
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, other: Self) -> Self
[src]
impl<F: Float> AddAssign<LogDomain<F>> for LogDomain<F>
[src]
fn add_assign(&mut self, other: Self)
[src]
impl<F: Float + Debug> SubAssign<LogDomain<F>> for LogDomain<F>
[src]
fn sub_assign(&mut self, other: Self)
[src]
impl<F: Float> MulAssign<LogDomain<F>> for LogDomain<F>
[src]
fn mul_assign(&mut self, other: Self)
[src]
impl<F: Float> DivAssign<LogDomain<F>> for LogDomain<F>
[src]
fn div_assign(&mut self, other: Self)
[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]
impl<F: Float> Zero for LogDomain<F>
[src]
fn zero() -> Self
[src]
fn is_zero(&self) -> bool
[src]
fn set_zero(&mut self)
[src]
Sets self
to the additive identity element of Self
, 0
.
impl<F: Float> One for LogDomain<F>
[src]
fn one() -> Self
[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]
Self: PartialEq<Self>,
Returns true
if self
is equal to the multiplicative identity. Read more
impl<F: Float + Serialize> Serialize for LogDomain<F>
[src]
impl<'de, F: Float + Deserialize<'de>> Deserialize<'de> for LogDomain<F>
[src]
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,