pub struct PositiveSign<T>(/* private fields */);Expand description
A floating-point number which is not NaN and whose sign bit is positive.
The allowed values consist of positive zero, positive infinity, and every value in between those. This set of values means that this type:
- Implements
Eqstraightforwardly; neither NaN nor signed zeroes can cause problems with using it as a map key for caching, interning, etc. - Is closed under multiplication and addition, so unlike
NotNan, cannot cause a panic from uncautious arithmetic.
The permitted values of a PositiveSign<T> are a subset of those of a NotNan<T>.
(This may not be guaranteed if T implements numeric traits in inconsistent ways,
but may be assumed for f32 and f64.)
The arithmetic behavior of PositiveSign<T> is not identical to T.
Specifically, the value of 0. * fXX::INFINITY is NaN, but the value of
PositiveSign(0.) * PositiveSign(fXX::INFINITY) is PositiveSign(0.) instead.
Our assumption here is that for the applications where PositiveSign is suitable, infinities
are either impossible or arise as “would be finite but it is too large to be represented”,
and do not arise as the reciprocal of zero, and thus we can treat “zero times anything
is zero” as being a more important property than “infinity times anything is infinity”.
Implementations§
Source§impl<T> PositiveSign<T>where
T: FloatCore,
impl<T> PositiveSign<T>where
T: FloatCore,
Sourcepub const unsafe fn new_unchecked(value: T) -> PositiveSign<T>
pub const unsafe fn new_unchecked(value: T) -> PositiveSign<T>
Construct PositiveSign without checking the value.
§Safety
value must not be NaN and must have a positive sign bit.
Note that value >= 0. is not a sufficient condition,
because it does not exclude negative zero.
Sourcepub const fn into_inner(self) -> T
pub const fn into_inner(self) -> T
Unwraps the value without modifying it.
Sourcepub fn floor(self) -> PositiveSign<T>
pub fn floor(self) -> PositiveSign<T>
Returns the largest integer less than or equal to self.
Sourcepub fn ceil(self) -> PositiveSign<T>
pub fn ceil(self) -> PositiveSign<T>
Returns the smallest integer greater than or equal to self.
Sourcepub fn round(self) -> PositiveSign<T>
pub fn round(self) -> PositiveSign<T>
Returns the nearest integer to self.
If a value is half-way between two integers, round up from 0.0.
Source§impl PositiveSign<f32>
impl PositiveSign<f32>
Sourcepub const INFINITY: PositiveSign<f32>
pub const INFINITY: PositiveSign<f32>
Positive infinity (∞).
Sourcepub const fn new_strict(value: f32) -> PositiveSign<f32>
pub const fn new_strict(value: f32) -> PositiveSign<f32>
Wraps the given value in PositiveSign.
- If
valueis positive (including positive infinity), returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis negative non-zero or NaN, panics.
Sourcepub const fn new_clamped(value: f32) -> PositiveSign<f32>
pub const fn new_clamped(value: f32) -> PositiveSign<f32>
Wraps the given value in PositiveSign.
- If the value is NaN, panics.
- If the value has a negative sign, it is replaced with positive zero.
Sourcepub fn saturating_sub(self, other: PositiveSign<f32>) -> PositiveSign<f32>
pub fn saturating_sub(self, other: PositiveSign<f32>) -> PositiveSign<f32>
Subtract other from self; if the result would be negative, it is zero instead.
Source§impl PositiveSign<f64>
impl PositiveSign<f64>
Sourcepub const INFINITY: PositiveSign<f64>
pub const INFINITY: PositiveSign<f64>
Positive infinity (∞).
Sourcepub const fn new_strict(value: f64) -> PositiveSign<f64>
pub const fn new_strict(value: f64) -> PositiveSign<f64>
Wraps the given value in PositiveSign.
- If
valueis positive (including positive infinity), returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis negative non-zero or NaN, panics.
Sourcepub const fn new_clamped(value: f64) -> PositiveSign<f64>
pub const fn new_clamped(value: f64) -> PositiveSign<f64>
Wraps the given value in PositiveSign.
- If the value is NaN, panics.
- If the value has a negative sign, it is replaced with positive zero.
Sourcepub fn saturating_sub(self, other: PositiveSign<f64>) -> PositiveSign<f64>
pub fn saturating_sub(self, other: PositiveSign<f64>) -> PositiveSign<f64>
Subtract other from self; if the result would be negative, it is zero instead.
Trait Implementations§
Source§impl<T> Add for PositiveSign<T>
impl<T> Add for PositiveSign<T>
Source§type Output = PositiveSign<T>
type Output = PositiveSign<T>
+ operator.Source§fn add(self, rhs: PositiveSign<T>) -> <PositiveSign<T> as Add>::Output
fn add(self, rhs: PositiveSign<T>) -> <PositiveSign<T> as Add>::Output
+ operation. Read moreSource§impl<T> AddAssign for PositiveSign<T>
impl<T> AddAssign for PositiveSign<T>
Source§fn add_assign(&mut self, rhs: PositiveSign<T>)
fn add_assign(&mut self, rhs: PositiveSign<T>)
+= operation. Read moreSource§impl<'a, T> Arbitrary<'a> for PositiveSign<T>
impl<'a, T> Arbitrary<'a> for PositiveSign<T>
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<PositiveSign<T>, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<PositiveSign<T>, Error>
Self from the given unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§impl<T> AsRef<T> for PositiveSign<T>
impl<T> AsRef<T> for PositiveSign<T>
Source§impl<T> Clone for PositiveSign<T>where
T: Clone,
impl<T> Clone for PositiveSign<T>where
T: Clone,
Source§fn clone(&self) -> PositiveSign<T>
fn clone(&self) -> PositiveSign<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> ConstOne for PositiveSign<T>
impl<T> ConstOne for PositiveSign<T>
Source§const ONE: PositiveSign<T>
const ONE: PositiveSign<T>
Self, 1.Source§impl<T> ConstZero for PositiveSign<T>
impl<T> ConstZero for PositiveSign<T>
Source§const ZERO: PositiveSign<T>
const ZERO: PositiveSign<T>
Self, 0.Source§impl<T> Debug for PositiveSign<T>where
T: Debug,
impl<T> Debug for PositiveSign<T>where
T: Debug,
Source§impl<T> Default for PositiveSign<T>
impl<T> Default for PositiveSign<T>
Source§fn default() -> PositiveSign<T>
fn default() -> PositiveSign<T>
The default is zero, regardless of what T::default() is.
Source§impl<'de, T> Deserialize<'de> for PositiveSign<T>where
T: Deserialize<'de>,
PositiveSign<T>: TryFrom<T>,
<PositiveSign<T> as TryFrom<T>>::Error: Error,
impl<'de, T> Deserialize<'de> for PositiveSign<T>where
T: Deserialize<'de>,
PositiveSign<T>: TryFrom<T>,
<PositiveSign<T> as TryFrom<T>>::Error: Error,
Source§fn deserialize<D>(
deserializer: D,
) -> Result<PositiveSign<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<PositiveSign<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<T> Display for PositiveSign<T>where
T: Display,
impl<T> Display for PositiveSign<T>where
T: Display,
Source§impl<T> Hash for PositiveSign<T>where
T: PrimitiveFloat,
impl<T> Hash for PositiveSign<T>where
T: PrimitiveFloat,
Source§impl<T> Mul<PositiveSign<T>> for ZeroOne<T>
impl<T> Mul<PositiveSign<T>> for ZeroOne<T>
Source§type Output = PositiveSign<T>
type Output = PositiveSign<T>
* operator.Source§fn mul(
self,
rhs: PositiveSign<T>,
) -> <ZeroOne<T> as Mul<PositiveSign<T>>>::Output
fn mul( self, rhs: PositiveSign<T>, ) -> <ZeroOne<T> as Mul<PositiveSign<T>>>::Output
* operation. Read moreSource§impl<T> Mul<ZeroOne<T>> for PositiveSign<T>
impl<T> Mul<ZeroOne<T>> for PositiveSign<T>
Source§impl<T> Mul for PositiveSign<T>
impl<T> Mul for PositiveSign<T>
Source§fn mul(self, rhs: PositiveSign<T>) -> <PositiveSign<T> as Mul>::Output
fn mul(self, rhs: PositiveSign<T>) -> <PositiveSign<T> as Mul>::Output
This multiplication operation differs from standard floating-point multiplication in that multiplying zero by positive infinity returns zero instead of NaN. This is necessary for the type to be closed under multiplication.
Source§type Output = PositiveSign<T>
type Output = PositiveSign<T>
* operator.Source§impl<T> MulAssign for PositiveSign<T>
impl<T> MulAssign for PositiveSign<T>
Source§fn mul_assign(&mut self, rhs: PositiveSign<T>)
fn mul_assign(&mut self, rhs: PositiveSign<T>)
*= operation. Read moreSource§impl<T> One for PositiveSign<T>
impl<T> One for PositiveSign<T>
Source§fn one() -> PositiveSign<T>
fn one() -> PositiveSign<T>
Source§impl<T> Ord for PositiveSign<T>where
T: FloatCore + PartialOrd,
impl<T> Ord for PositiveSign<T>where
T: FloatCore + PartialOrd,
Source§fn cmp(&self, other: &PositiveSign<T>) -> Ordering
fn cmp(&self, other: &PositiveSign<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T> PartialEq<T> for PositiveSign<T>where
T: PartialEq,
impl<T> PartialEq<T> for PositiveSign<T>where
T: PartialEq,
Source§impl<T> PartialEq for PositiveSign<T>where
T: PartialEq,
impl<T> PartialEq for PositiveSign<T>where
T: PartialEq,
Source§impl<T> PartialOrd<T> for PositiveSign<T>where
T: PartialOrd,
impl<T> PartialOrd<T> for PositiveSign<T>where
T: PartialOrd,
Source§impl<T> PartialOrd for PositiveSign<T>where
T: FloatCore + PartialOrd,
impl<T> PartialOrd for PositiveSign<T>where
T: FloatCore + PartialOrd,
Source§impl<T> Serialize for PositiveSign<T>where
T: Serialize,
impl<T> Serialize for PositiveSign<T>where
T: Serialize,
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<T> Sum for PositiveSign<T>
impl<T> Sum for PositiveSign<T>
Source§fn sum<I>(iter: I) -> PositiveSign<T>where
I: Iterator<Item = PositiveSign<T>>,
fn sum<I>(iter: I) -> PositiveSign<T>where
I: Iterator<Item = PositiveSign<T>>,
Self from the elements by “summing up”
the items.Source§impl<T> TryFrom<NotNan<T>> for PositiveSign<T>
impl<T> TryFrom<NotNan<T>> for PositiveSign<T>
Source§fn try_from(
value: NotNan<T>,
) -> Result<PositiveSign<T>, <PositiveSign<T> as TryFrom<NotNan<T>>>::Error>
fn try_from( value: NotNan<T>, ) -> Result<PositiveSign<T>, <PositiveSign<T> as TryFrom<NotNan<T>>>::Error>
Checks that value is non-negative.
- If
valueis positive (including positive infinity), returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis negative non-zero or NaN, returns an error.
Source§type Error = NotPositiveSign<T>
type Error = NotPositiveSign<T>
Source§impl TryFrom<f32> for PositiveSign<f32>
impl TryFrom<f32> for PositiveSign<f32>
Source§fn try_from(
value: f32,
) -> Result<PositiveSign<f32>, <PositiveSign<f32> as TryFrom<f32>>::Error>
fn try_from( value: f32, ) -> Result<PositiveSign<f32>, <PositiveSign<f32> as TryFrom<f32>>::Error>
Checks that value is non-negative and non-NaN.
- If
valueis positive (including positive infinity), returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis negative non-zero or NaN, returns an error.
Source§type Error = NotPositiveSign<f32>
type Error = NotPositiveSign<f32>
Source§impl TryFrom<f64> for PositiveSign<f64>
impl TryFrom<f64> for PositiveSign<f64>
Source§fn try_from(
value: f64,
) -> Result<PositiveSign<f64>, <PositiveSign<f64> as TryFrom<f64>>::Error>
fn try_from( value: f64, ) -> Result<PositiveSign<f64>, <PositiveSign<f64> as TryFrom<f64>>::Error>
Checks that value is non-negative and non-NaN.
- If
valueis positive (including positive infinity), returns wrappedvalue. - If
valueis zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0. - If
valueis negative non-zero or NaN, returns an error.
Source§type Error = NotPositiveSign<f64>
type Error = NotPositiveSign<f64>
Source§impl<T> Zero for PositiveSign<T>
impl<T> Zero for PositiveSign<T>
impl<T> Copy for PositiveSign<T>where
T: Copy,
impl<T> Eq for PositiveSign<T>where
T: PartialEq,
impl<T> StructuralPartialEq for PositiveSign<T>
Auto Trait Implementations§
impl<T> Freeze for PositiveSign<T>where
T: Freeze,
impl<T> RefUnwindSafe for PositiveSign<T>where
T: RefUnwindSafe,
impl<T> Send for PositiveSign<T>where
T: Send,
impl<T> Sync for PositiveSign<T>where
T: Sync,
impl<T> Unpin for PositiveSign<T>where
T: Unpin,
impl<T> UnwindSafe for PositiveSign<T>where
T: 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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more