pub struct LogDomain<F: Float>(/* private fields */);
Expand description
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!(),
}
Implementations§
Trait Implementations§
Source§impl<F: Float> Add for LogDomain<F>
An impl
of Add
that uses only two applications of transcendental functions
(exp
and ln_1p
) to increase precision.
impl<F: Float> Add for LogDomain<F>
An impl
of Add
that uses only two applications of transcendental functions
(exp
and ln_1p
) to increase precision.
Source§impl<F: Float> AddAssign for LogDomain<F>
impl<F: Float> AddAssign for LogDomain<F>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+=
operation. Read moreSource§impl<'de, F: Float + Deserialize<'de>> Deserialize<'de> for LogDomain<F>
impl<'de, F: Float + Deserialize<'de>> Deserialize<'de> for LogDomain<F>
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl<F: Float> DivAssign for LogDomain<F>
impl<F: Float> DivAssign for LogDomain<F>
Source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
Performs the
/=
operation. Read moreSource§impl<F: Float> MulAssign for LogDomain<F>
impl<F: Float> MulAssign for LogDomain<F>
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs the
*=
operation. Read moreSource§impl<F: Float> Ord for LogDomain<F>
An impl
of Ord
that defines
Exp(NaN) = Exp(NaN)
,
Exp(NaN) < Exp(y)
, and
Exp(x) < Exp(y)
for x < y
.
impl<F: Float> Ord for LogDomain<F>
An impl
of Ord
that defines
Exp(NaN) = Exp(NaN)
,
Exp(NaN) < Exp(y)
, and
Exp(x) < Exp(y)
for x < y
.
Source§impl<F: Float> PartialEq for LogDomain<F>
An impl
of PartialEq
that defines
Exp(NaN) = Exp(NaN)
and
Exp(x) = Exp(y)
for x - y < F::EPSILON
.
impl<F: Float> PartialEq for LogDomain<F>
An impl
of PartialEq
that defines
Exp(NaN) = Exp(NaN)
and
Exp(x) = Exp(y)
for x - y < F::EPSILON
.
Source§impl<F: PartialOrd + Float> PartialOrd for LogDomain<F>
impl<F: PartialOrd + Float> PartialOrd for LogDomain<F>
Source§impl<F: Float + Debug> Sub for LogDomain<F>
An impl
of Sub
that uses only two applications of transcendental functions
(exp_m1
and ln
) to increase precision.
impl<F: Float + Debug> Sub for LogDomain<F>
An impl
of Sub
that uses only two applications of transcendental functions
(exp_m1
and ln
) to increase precision.
Source§impl<F: Float + Debug> SubAssign for LogDomain<F>
impl<F: Float + Debug> SubAssign for LogDomain<F>
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-=
operation. Read moreimpl<F: Copy + Float> Copy for LogDomain<F>
impl<F: Float> Eq for LogDomain<F>
Auto Trait Implementations§
impl<F> Freeze for LogDomain<F>where
F: Freeze,
impl<F> RefUnwindSafe for LogDomain<F>where
F: RefUnwindSafe,
impl<F> Send for LogDomain<F>where
F: Send,
impl<F> Sync for LogDomain<F>where
F: Sync,
impl<F> Unpin for LogDomain<F>where
F: Unpin,
impl<F> UnwindSafe for LogDomain<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more