Struct decorum::ConstrainedFloat
source · [−]#[repr(transparent)]pub struct ConstrainedFloat<T, P> { /* private fields */ }
Expand description
Floating-point proxy that provides a total ordering, equivalence, hashing, and constraints.
ConstrainedFloat
wraps primitive floating-point types and provides
implementations for numeric traits using a total ordering, including Ord
,
Eq
, and Hash
. ConstrainedFloat
supports various constraints on the
class of values that may be represented and panics if these constraints are
violated.
This type is re-exported but should not (and cannot) be used directly. Use
the type aliases Total
, NotNan
, and Finite
instead.
Total Ordering
All proxy types use the following total ordering:
$$-\infin<\cdots<0<\cdots<\infin<\text{NaN}$$
See the cmp
module for a description of the total ordering used to
implement Ord
and Eq
.
Constraints
Constraints restrict the set of values that a proxy may take by disallowing certain classes or subsets of those values. If a constraint is violated (because a proxy type would need to take a value it disallows), the operation panics.
Constraints may disallow two broad classes of floating-point values:
infinities and NaN
s. Constraints are exposed by the Total
, NotNan
, and
Finite
type definitions. Note that Total
uses a unit constraint, which
enforces no constraints at all and never panics.
Implementations
sourceimpl<T, P> ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcepub fn from_inner(value: T) -> Self
pub fn from_inner(value: T) -> Self
Converts a primitive floating-point value into a proxy.
The same behavior is provided by an implementation of the From
trait.
Panics
This conversion and the implementation of the From
trait will panic
if the primitive floating-point value violates the constraints of the
proxy.
Examples
Converting primitive floating-point values into proxies:
use decorum::R64;
fn f(x: R64) -> R64 {
x * 2.0
}
// Conversion using `from_inner`.
let y = f(R64::from_inner(2.0));
// Conversion using `From`/`Into`.
let z = f(2.0.into());
Performing a conversion that panics:
use decorum::R64;
// `R64` does not allow `NaN`s, but `0.0 / 0.0` produces a `NaN`.
let x = R64::from_inner(0.0 / 0.0); // Panics.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Converts a proxy into a primitive floating-point value.
Examples
Converting a proxy into a primitive floating-point value:
use decorum::R64;
fn f() -> R64 {
// ...
}
let x: f64 = f().into_inner();
sourcepub fn from_subset<Q>(other: ConstrainedFloat<T, Q>) -> Self where
Q: Constraint<T> + SubsetOf<P>,
pub fn from_subset<Q>(other: ConstrainedFloat<T, Q>) -> Self where
Q: Constraint<T> + SubsetOf<P>,
Converts a proxy into another proxy that is capable of representing a superset of the values that are members of its constraint.
Examples
Converting between compatible proxy types:
use decorum::{N64, R64};
use num::Zero;
let x = R64::zero();
let y = N64::from_subset(x);
sourcepub fn into_superset<Q>(self) -> ConstrainedFloat<T, Q> where
Q: Constraint<T> + SupersetOf<P>,
pub fn into_superset<Q>(self) -> ConstrainedFloat<T, Q> where
Q: Constraint<T> + SupersetOf<P>,
Converts a proxy into another proxy that is capable of representing a superset of the values that are members of its constraint.
Examples
Converting between compatible proxy types:
use decorum::{N64, R64};
use num::Zero;
let x = R64::zero();
let y: N64 = x.into_superset();
Trait Implementations
sourceimpl<T, P> AbsDiffEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: AbsDiffEq<Epsilon = T> + Float + Primitive,
P: Constraint<T>,
impl<T, P> AbsDiffEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: AbsDiffEq<Epsilon = T> + Float + Primitive,
P: Constraint<T>,
type Epsilon = ConstrainedFloat<T, P>
type Epsilon = ConstrainedFloat<T, P>
Used for specifying relative comparisons.
sourcefn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
The default tolerance to use when testing values that are close together. Read more
sourcefn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
A test for equality that uses the absolute difference to compute the approximate equality of two numbers. Read more
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of ApproxEq::abs_diff_eq
.
sourceimpl<T, P> Add<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Add<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Add<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Add<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> AddAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> AddAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the +=
operation. Read more
sourceimpl<T, P> AddAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> AddAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
Performs the +=
operation. Read more
sourceimpl<T, P> AsRef<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> AsRef<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Bounded for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Bounded for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T: Clone, P: Clone> Clone for ConstrainedFloat<T, P>
impl<T: Clone, P: Clone> Clone for ConstrainedFloat<T, P>
sourcefn clone(&self) -> ConstrainedFloat<T, P>
fn clone(&self) -> ConstrainedFloat<T, P>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T, P> Default for ConstrainedFloat<T, P> where
T: Default + Float + Primitive,
P: Constraint<T>,
impl<T, P> Default for ConstrainedFloat<T, P> where
T: Default + Float + Primitive,
P: Constraint<T>,
sourceimpl<'de, T, P> Deserialize<'de> for ConstrainedFloat<T, P> where
T: Deserialize<'de>,
impl<'de, T, P> Deserialize<'de> for ConstrainedFloat<T, P> where
T: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<T, P> Display for ConstrainedFloat<T, P> where
T: Display + Float + Primitive,
P: Constraint<T>,
impl<T, P> Display for ConstrainedFloat<T, P> where
T: Display + Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Div<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Div<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Div<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Div<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> DivAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> DivAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
Performs the /=
operation. Read more
sourceimpl<T, P> DivAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> DivAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn div_assign(&mut self, other: T)
fn div_assign(&mut self, other: T)
Performs the /=
operation. Read more
sourceimpl<T, P> Encoding for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Encoding for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
const MAX: Self = ConstrainedFloat::from_inner_unchecked(T::MAX)
const MIN: Self = ConstrainedFloat::from_inner_unchecked(T::MIN)
const MIN_POSITIVE: Self = ConstrainedFloat::from_inner_unchecked(T::MIN_POSITIVE)
const EPSILON: Self = ConstrainedFloat::from_inner_unchecked(T::EPSILON)
fn classify(self) -> FpCategory
fn is_normal(self) -> bool
fn is_sign_positive(self) -> bool
fn is_sign_negative(self) -> bool
fn integer_decode(self) -> (u64, i16, i8)
sourceimpl<T, P> Float for ConstrainedFloat<T, P> where
T: Float + ForeignFloat + IntrinsicOrd + Primitive,
P: Constraint<T> + Member<InfiniteClass> + Member<NanClass>,
impl<T, P> Float for ConstrainedFloat<T, P> where
T: Float + ForeignFloat + IntrinsicOrd + Primitive,
P: Constraint<T> + Member<InfiniteClass> + Member<NanClass>,
sourcefn neg_infinity() -> Self
fn neg_infinity() -> Self
Returns the negative infinite value. Read more
sourcefn is_infinite(self) -> bool
fn is_infinite(self) -> bool
Returns true
if this value is positive infinity or negative infinity and
false otherwise. Read more
sourcefn max_value() -> Self
fn max_value() -> Self
Returns the largest finite value that this type can represent. Read more
sourcefn min_value() -> Self
fn min_value() -> Self
Returns the smallest finite value that this type can represent. Read more
sourcefn min_positive_value() -> Self
fn min_positive_value() -> Self
Returns the smallest positive, normalized value that this type can represent. Read more
sourcefn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
Returns true
if self
is positive, including +0.0
,
Float::infinity()
, and since Rust 1.20 also Float::nan()
. Read more
sourcefn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
Returns true
if self
is negative, including -0.0
,
Float::neg_infinity()
, and since Rust 1.20 also -Float::nan()
. Read more
sourcefn abs(self) -> Self
fn abs(self) -> Self
Computes the absolute value of self
. Returns Float::nan()
if the
number is Float::nan()
. Read more
sourcefn classify(self) -> FpCategory
fn classify(self) -> FpCategory
Returns the floating point category of the number. If only one property is going to be tested, it is generally faster to use the specific predicate instead. Read more
sourcefn integer_decode(self) -> (u64, i16, i8)
fn integer_decode(self) -> (u64, i16, i8)
Returns the mantissa, base 2 exponent, and sign as integers, respectively.
The original number can be recovered by sign * mantissa * 2 ^ exponent
. Read more
sourcefn ceil(self) -> Self
fn ceil(self) -> Self
Returns the smallest integer greater than or equal to a number. Read more
sourcefn round(self) -> Self
fn round(self) -> Self
Returns the nearest integer to a number. Round half-way cases away from
0.0
. Read more
sourcefn mul_add(self, a: Self, b: Self) -> Self
fn mul_add(self, a: Self, b: Self) -> Self
Fused multiply-add. Computes (self * a) + b
with only one rounding
error, yielding a more accurate result than an unfused multiply-add. Read more
sourcefn exp_m1(self) -> Self
fn exp_m1(self) -> Self
Returns e^(self) - 1
in a way that is accurate even if the
number is close to zero. Read more
sourcefn log(self, base: Self) -> Self
fn log(self, base: Self) -> Self
Returns the logarithm of the number with respect to an arbitrary base. Read more
sourcefn ln_1p(self) -> Self
fn ln_1p(self) -> Self
Returns ln(1+n)
(natural logarithm) more accurately than if
the operations were performed separately. Read more
sourcefn hypot(self, other: Self) -> Self
fn hypot(self, other: Self) -> Self
Calculate the length of the hypotenuse of a right-angle triangle given
legs of length x
and y
. Read more
sourcefn asin(self) -> Self
fn asin(self) -> Self
Computes the arcsine of a number. Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1]. Read more
sourcefn acos(self) -> Self
fn acos(self) -> Self
Computes the arccosine of a number. Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1]. Read more
sourcefn atan(self) -> Self
fn atan(self) -> Self
Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2]; Read more
sourcefn atan2(self, other: Self) -> Self
fn atan2(self, other: Self) -> Self
Computes the four quadrant arctangent of self
(y
) and other
(x
). Read more
sourcefn sin_cos(self) -> (Self, Self)
fn sin_cos(self) -> (Self, Self)
Simultaneously computes the sine and cosine of the number, x
. Returns
(sin(x), cos(x))
. Read more
sourcefn to_degrees(self) -> Self
fn to_degrees(self) -> Self
Converts radians to degrees. Read more
sourcefn to_radians(self) -> Self
fn to_radians(self) -> Self
Converts degrees to radians. Read more
sourceimpl<T, P> FloatConst for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> FloatConst for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn FRAC_1_SQRT_2() -> Self
fn FRAC_1_SQRT_2() -> Self
Return 1.0 / sqrt(2.0)
.
sourcefn FRAC_2_SQRT_PI() -> Self
fn FRAC_2_SQRT_PI() -> Self
Return 2.0 / sqrt(π)
.
sourceimpl<T> From<ConstrainedFloat<T, FiniteConstraint<T>>> for Total<T> where
T: Float + Primitive,
impl<T> From<ConstrainedFloat<T, FiniteConstraint<T>>> for Total<T> where
T: Float + Primitive,
sourceimpl<T> From<ConstrainedFloat<T, FiniteConstraint<T>>> for NotNan<T> where
T: Float + Primitive,
impl<T> From<ConstrainedFloat<T, FiniteConstraint<T>>> for NotNan<T> where
T: Float + Primitive,
sourceimpl<T> From<ConstrainedFloat<T, NotNanConstraint<T>>> for Total<T> where
T: Float + Primitive,
impl<T> From<ConstrainedFloat<T, NotNanConstraint<T>>> for Total<T> where
T: Float + Primitive,
sourceimpl<P> From<ConstrainedFloat<f32, P>> for f32 where
P: Constraint<f32>,
impl<P> From<ConstrainedFloat<f32, P>> for f32 where
P: Constraint<f32>,
sourcefn from(value: ConstrainedFloat<f32, P>) -> Self
fn from(value: ConstrainedFloat<f32, P>) -> Self
Converts to this type from the input type.
sourceimpl<P> From<ConstrainedFloat<f64, P>> for f64 where
P: Constraint<f64>,
impl<P> From<ConstrainedFloat<f64, P>> for f64 where
P: Constraint<f64>,
sourcefn from(value: ConstrainedFloat<f64, P>) -> Self
fn from(value: ConstrainedFloat<f64, P>) -> Self
Converts to this type from the input type.
sourceimpl<T, P> From<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> From<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> FromPrimitive for ConstrainedFloat<T, P> where
T: Float + FromPrimitive + Primitive,
P: Constraint<T>,
impl<T, P> FromPrimitive for ConstrainedFloat<T, P> where
T: Float + FromPrimitive + Primitive,
P: Constraint<T>,
sourcefn from_i8(value: i8) -> Option<Self>
fn from_i8(value: i8) -> Option<Self>
Converts an i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_u8(value: u8) -> Option<Self>
fn from_u8(value: u8) -> Option<Self>
Converts an u8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_i16(value: i16) -> Option<Self>
fn from_i16(value: i16) -> Option<Self>
Converts an i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_u16(value: u16) -> Option<Self>
fn from_u16(value: u16) -> Option<Self>
Converts an u16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_i32(value: i32) -> Option<Self>
fn from_i32(value: i32) -> Option<Self>
Converts an i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_u32(value: u32) -> Option<Self>
fn from_u32(value: u32) -> Option<Self>
Converts an u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_i64(value: i64) -> Option<Self>
fn from_i64(value: i64) -> Option<Self>
Converts an i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_u64(value: u64) -> Option<Self>
fn from_u64(value: u64) -> Option<Self>
Converts an u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_isize(value: isize) -> Option<Self>
fn from_isize(value: isize) -> Option<Self>
Converts an isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_usize(value: usize) -> Option<Self>
fn from_usize(value: usize) -> Option<Self>
Converts a usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_f32(value: f32) -> Option<Self>
fn from_f32(value: f32) -> Option<Self>
Converts a f32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourcefn from_f64(value: f64) -> Option<Self>
fn from_f64(value: f64) -> Option<Self>
Converts a f64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
sourceimpl<T, P> FromStr for ConstrainedFloat<T, P> where
T: Float + FromStr + Primitive,
P: Constraint<T>,
impl<T, P> FromStr for ConstrainedFloat<T, P> where
T: Float + FromStr + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Hash for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Hash for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Infinite for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T> + Member<InfiniteClass>,
impl<T, P> Infinite for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T> + Member<InfiniteClass>,
const INFINITY: Self = ConstrainedFloat::from_inner_unchecked(T::INFINITY)
const NEG_INFINITY: Self = ConstrainedFloat::from_inner_unchecked(T::NEG_INFINITY)
fn is_infinite(self) -> bool
fn is_finite(self) -> bool
sourceimpl<T, P> IntrinsicOrd for ConstrainedFloat<T, P> where
T: Float + IntrinsicOrd + Primitive,
P: Constraint<T>,
impl<T, P> IntrinsicOrd for ConstrainedFloat<T, P> where
T: Float + IntrinsicOrd + Primitive,
P: Constraint<T>,
sourcefn is_undefined(&self) -> bool
fn is_undefined(&self) -> bool
Returns true
if a value encodes undefined, otherwise false
. Read more
sourcefn min_max_or_undefined(&self, other: &Self) -> (Self, Self)
fn min_max_or_undefined(&self, other: &Self) -> (Self, Self)
Compares two values and returns their pairwise minimum and maximum. Read more
fn min_or_undefined(&self, other: &Self) -> Self
fn max_or_undefined(&self, other: &Self) -> Self
sourceimpl<T, P> LowerExp for ConstrainedFloat<T, P> where
T: Float + LowerExp + Primitive,
P: Constraint<T>,
impl<T, P> LowerExp for ConstrainedFloat<T, P> where
T: Float + LowerExp + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Mul<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Mul<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Mul<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Mul<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> MulAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> MulAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs the *=
operation. Read more
sourceimpl<T, P> MulAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> MulAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn mul_assign(&mut self, other: T)
fn mul_assign(&mut self, other: T)
Performs the *=
operation. Read more
sourceimpl<T, P> Nan for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T> + Member<NanClass>,
impl<T, P> Nan for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T> + Member<NanClass>,
sourceimpl<T, P> Neg for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Neg for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Num for ConstrainedFloat<T, P> where
Self: PartialEq,
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Num for ConstrainedFloat<T, P> where
Self: PartialEq,
T: Float + Primitive,
P: Constraint<T>,
type FromStrRadixErr = ()
sourcefn from_str_radix(
source: &str,
radix: u32
) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(
source: &str,
radix: u32
) -> Result<Self, Self::FromStrRadixErr>
Convert from a string and radix (typically 2..=36
). Read more
sourceimpl<T, P> NumCast for ConstrainedFloat<T, P> where
T: Float + NumCast + Primitive + ToPrimitive,
P: Constraint<T>,
impl<T, P> NumCast for ConstrainedFloat<T, P> where
T: Float + NumCast + Primitive + ToPrimitive,
P: Constraint<T>,
sourcefn from<U>(value: U) -> Option<Self> where
U: ToPrimitive,
fn from<U>(value: U) -> Option<Self> where
U: ToPrimitive,
Creates a number from another value that can be converted into
a primitive via the ToPrimitive
trait. If the source value cannot be
represented by the target type, then None
is returned. Read more
sourceimpl<T, P> One for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> One for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Ord for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Ord for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> PartialEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> PartialEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> PartialEq<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> PartialEq<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> PartialOrd<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> PartialOrd<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<T, P> PartialOrd<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> PartialOrd<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn partial_cmp(&self, other: &T) -> Option<Ordering>
fn partial_cmp(&self, other: &T) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<T, P> Product<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Product<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Real for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Real for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
const E: Self = ConstrainedFloat::from_inner_unchecked(Real::E)
const PI: Self = ConstrainedFloat::from_inner_unchecked(Real::PI)
const FRAC_1_PI: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_1_PI)
const FRAC_2_PI: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_2_PI)
const FRAC_2_SQRT_PI: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_2_SQRT_PI)
const FRAC_PI_2: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_PI_2)
const FRAC_PI_3: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_PI_3)
const FRAC_PI_4: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_PI_4)
const FRAC_PI_6: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_PI_6)
const FRAC_PI_8: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_PI_8)
const SQRT_2: Self = ConstrainedFloat::from_inner_unchecked(Real::SQRT_2)
const FRAC_1_SQRT_2: Self = ConstrainedFloat::from_inner_unchecked(Real::FRAC_1_SQRT_2)
const LN_2: Self = ConstrainedFloat::from_inner_unchecked(Real::LN_2)
const LN_10: Self = ConstrainedFloat::from_inner_unchecked(Real::LN_10)
const LOG2_E: Self = ConstrainedFloat::from_inner_unchecked(Real::LOG2_E)
const LOG10_E: Self = ConstrainedFloat::from_inner_unchecked(Real::LOG10_E)
fn floor(self) -> Self
fn ceil(self) -> Self
fn round(self) -> Self
fn trunc(self) -> Self
fn fract(self) -> Self
fn recip(self) -> Self
fn mul_add(self, a: Self, b: Self) -> Self
fn powi(self, n: i32) -> Self
fn powf(self, n: Self) -> Self
fn sqrt(self) -> Self
fn cbrt(self) -> Self
fn exp(self) -> Self
fn exp2(self) -> Self
fn exp_m1(self) -> Self
fn log(self, base: Self) -> Self
fn ln(self) -> Self
fn log2(self) -> Self
fn log10(self) -> Self
fn ln_1p(self) -> Self
fn hypot(self, other: Self) -> Self
fn sin(self) -> Self
fn cos(self) -> Self
fn tan(self) -> Self
fn asin(self) -> Self
fn acos(self) -> Self
fn atan(self) -> Self
fn atan2(self, other: Self) -> Self
fn sin_cos(self) -> (Self, Self)
fn sinh(self) -> Self
fn cosh(self) -> Self
fn tanh(self) -> Self
fn asinh(self) -> Self
fn acosh(self) -> Self
fn atanh(self) -> Self
sourceimpl<T, P> RelativeEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive + RelativeEq<Epsilon = T>,
P: Constraint<T>,
impl<T, P> RelativeEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive + RelativeEq<Epsilon = T>,
P: Constraint<T>,
sourcefn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
The default relative tolerance for testing values that are far-apart. Read more
sourcefn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
A test for equality that uses a relative comparison if the values are far apart.
fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
The inverse of ApproxEq::relative_eq
.
sourceimpl<T, P> Rem<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Rem<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Rem<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Rem<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> RemAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> RemAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn rem_assign(&mut self, other: Self)
fn rem_assign(&mut self, other: Self)
Performs the %=
operation. Read more
sourceimpl<T, P> RemAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> RemAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn rem_assign(&mut self, other: T)
fn rem_assign(&mut self, other: T)
Performs the %=
operation. Read more
sourceimpl<T, P> Serialize for ConstrainedFloat<T, P> where
T: Serialize,
impl<T, P> Serialize for ConstrainedFloat<T, P> where
T: Serialize,
sourceimpl<T, P> Signed for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Signed for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Returns true if the number is positive and false if the number is zero or negative.
sourcefn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Returns true if the number is negative and false if the number is zero or positive.
sourceimpl<T, P> Sub<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Sub<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> Sub<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Sub<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> SubAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> SubAssign<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the -=
operation. Read more
sourceimpl<T, P> SubAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> SubAssign<T> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn sub_assign(&mut self, other: T)
fn sub_assign(&mut self, other: T)
Performs the -=
operation. Read more
sourceimpl<T, P> Sum<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Sum<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourceimpl<T, P> ToCanonicalBits for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> ToCanonicalBits for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
sourcefn to_canonical_bits(self) -> u64
fn to_canonical_bits(self) -> u64
Conversion to a canonical representation. Read more
sourceimpl<T, P> ToPrimitive for ConstrainedFloat<T, P> where
T: Float + Primitive + ToPrimitive,
P: Constraint<T>,
impl<T, P> ToPrimitive for ConstrainedFloat<T, P> where
T: Float + Primitive + ToPrimitive,
P: Constraint<T>,
sourcefn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
Converts the value of self
to an i8
. If the value cannot be
represented by an i8
, then None
is returned. Read more
sourcefn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
Converts the value of self
to a u8
. If the value cannot be
represented by a u8
, then None
is returned. Read more
sourcefn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
Converts the value of self
to an i16
. If the value cannot be
represented by an i16
, then None
is returned. Read more
sourcefn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
Converts the value of self
to a u16
. If the value cannot be
represented by a u16
, then None
is returned. Read more
sourcefn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
Converts the value of self
to an i32
. If the value cannot be
represented by an i32
, then None
is returned. Read more
sourcefn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
Converts the value of self
to a u32
. If the value cannot be
represented by a u32
, then None
is returned. Read more
sourcefn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
Converts the value of self
to an i64
. If the value cannot be
represented by an i64
, then None
is returned. Read more
sourcefn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
Converts the value of self
to a u64
. If the value cannot be
represented by a u64
, then None
is returned. Read more
sourcefn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
Converts the value of self
to an isize
. If the value cannot be
represented by an isize
, then None
is returned. Read more
sourcefn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
Converts the value of self
to a usize
. If the value cannot be
represented by a usize
, then None
is returned. Read more
sourcefn to_f32(&self) -> Option<f32>
fn to_f32(&self) -> Option<f32>
Converts the value of self
to an f32
. Overflows may map to positive
or negative inifinity, otherwise None
is returned if the value cannot
be represented by an f32
. Read more
sourcefn to_f64(&self) -> Option<f64>
fn to_f64(&self) -> Option<f64>
Converts the value of self
to an f64
. Overflows may map to positive
or negative inifinity, otherwise None
is returned if the value cannot
be represented by an f64
. Read more
sourceimpl<T, P> UlpsEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive + UlpsEq<Epsilon = T>,
P: Constraint<T>,
impl<T, P> UlpsEq<ConstrainedFloat<T, P>> for ConstrainedFloat<T, P> where
T: Float + Primitive + UlpsEq<Epsilon = T>,
P: Constraint<T>,
sourceimpl<T, P> UpperExp for ConstrainedFloat<T, P> where
T: Float + Primitive + UpperExp,
P: Constraint<T>,
impl<T, P> UpperExp for ConstrainedFloat<T, P> where
T: Float + Primitive + UpperExp,
P: Constraint<T>,
sourceimpl<T, P> Zero for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T, P> Zero for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
impl<T: Copy, P: Copy> Copy for ConstrainedFloat<T, P>
impl<T, P> Eq for ConstrainedFloat<T, P> where
T: Float + Primitive,
P: Constraint<T>,
Auto Trait Implementations
impl<T, P> RefUnwindSafe for ConstrainedFloat<T, P> where
P: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, P> Send for ConstrainedFloat<T, P> where
P: Send,
T: Send,
impl<T, P> Sync for ConstrainedFloat<T, P> where
P: Sync,
T: Sync,
impl<T, P> Unpin for ConstrainedFloat<T, P> where
P: Unpin,
T: Unpin,
impl<T, P> UnwindSafe for ConstrainedFloat<T, P> where
P: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> LowerBounded for T where
T: Bounded,
impl<T> LowerBounded for T where
T: Bounded,
sourceimpl<T> Real for T where
T: Float,
impl<T> Real for T where
T: Float,
sourcefn min_positive_value() -> T
fn min_positive_value() -> T
Returns the smallest positive, normalized value that this type can represent. Read more
sourcefn round(self) -> T
fn round(self) -> T
Returns the nearest integer to a number. Round half-way cases away from
0.0
. Read more
sourcefn abs(self) -> T
fn abs(self) -> T
Computes the absolute value of self
. Returns Float::nan()
if the
number is Float::nan()
. Read more
sourcefn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
Returns true
if self
is positive, including +0.0
,
Float::infinity()
, and with newer versions of Rust f64::NAN
. Read more
sourcefn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
Returns true
if self
is negative, including -0.0
,
Float::neg_infinity()
, and with newer versions of Rust -f64::NAN
. Read more
sourcefn mul_add(self, a: T, b: T) -> T
fn mul_add(self, a: T, b: T) -> T
Fused multiply-add. Computes (self * a) + b
with only one rounding
error, yielding a more accurate result than an unfused multiply-add. Read more
sourcefn log(self, base: T) -> T
fn log(self, base: T) -> T
Returns the logarithm of the number with respect to an arbitrary base. Read more
sourcefn to_degrees(self) -> T
fn to_degrees(self) -> T
Converts radians to degrees. Read more
sourcefn to_radians(self) -> T
fn to_radians(self) -> T
Converts degrees to radians. Read more
sourcefn hypot(self, other: T) -> T
fn hypot(self, other: T) -> T
Calculate the length of the hypotenuse of a right-angle triangle given
legs of length x
and y
. Read more
sourcefn asin(self) -> T
fn asin(self) -> T
Computes the arcsine of a number. Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1]. Read more
sourcefn acos(self) -> T
fn acos(self) -> T
Computes the arccosine of a number. Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1]. Read more
sourcefn atan(self) -> T
fn atan(self) -> T
Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2]; Read more
sourcefn atan2(self, other: T) -> T
fn atan2(self, other: T) -> T
Computes the four quadrant arctangent of self
(y
) and other
(x
). Read more
sourcefn sin_cos(self) -> (T, T)
fn sin_cos(self) -> (T, T)
Simultaneously computes the sine and cosine of the number, x
. Returns
(sin(x), cos(x))
. Read more
sourcefn exp_m1(self) -> T
fn exp_m1(self) -> T
Returns e^(self) - 1
in a way that is accurate even if the
number is close to zero. Read more