PositiveSign

Struct PositiveSign 

Source
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 Eq straightforwardly; 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,

Source

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.

Source

pub const fn into_inner(self) -> T

Unwraps the value without modifying it.

Source

pub fn floor(self) -> PositiveSign<T>

Returns the largest integer less than or equal to self.

Source

pub fn ceil(self) -> PositiveSign<T>

Returns the smallest integer greater than or equal to self.

Source

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

pub fn is_finite(&self) -> bool

Returns whether the value is finite.

Since the value is statically guaranteed to be neither NaN nor negative, the only case where this returns false is when the value is positive infinity.

Source

pub fn clamp_01(self) -> ZeroOne<T>

Convert to ZeroOne, replacing too-large values with 1.0.

Source§

impl PositiveSign<f32>

Source

pub const INFINITY: PositiveSign<f32>

Positive infinity (∞).

Source

pub const fn new_strict(value: f32) -> PositiveSign<f32>

Wraps the given value in PositiveSign.

  • If value is positive (including positive infinity), returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is negative non-zero or NaN, panics.
Source

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.
Source

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>

Source

pub const INFINITY: PositiveSign<f64>

Positive infinity (∞).

Source

pub const fn new_strict(value: f64) -> PositiveSign<f64>

Wraps the given value in PositiveSign.

  • If value is positive (including positive infinity), returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is negative non-zero or NaN, panics.
Source

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.
Source

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>
where T: FloatCore<Output = T> + Add,

Source§

type Output = PositiveSign<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: PositiveSign<T>) -> <PositiveSign<T> as Add>::Output

Performs the + operation. Read more
Source§

impl<T> AddAssign for PositiveSign<T>
where T: FloatCore<Output = T> + Add,

Source§

fn add_assign(&mut self, rhs: PositiveSign<T>)

Performs the += operation. Read more
Source§

impl<'a, T> Arbitrary<'a> for PositiveSign<T>
where NotNan<T>: Arbitrary<'a> + Neg<Output = NotNan<T>> + Copy, PositiveSign<T>: TryFrom<NotNan<T>>,

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<PositiveSign<T>, Error>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

impl<T> AsRef<T> for PositiveSign<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Clone for PositiveSign<T>
where T: Clone,

Source§

fn clone(&self) -> PositiveSign<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> ConstOne for PositiveSign<T>
where T: FloatCore + ConstOne,

Source§

const ONE: PositiveSign<T>

The multiplicative identity element of Self, 1.
Source§

impl<T> ConstZero for PositiveSign<T>
where T: FloatCore + ConstZero,

Source§

const ZERO: PositiveSign<T>

The additive identity element of Self, 0.
Source§

impl<T> Debug for PositiveSign<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for PositiveSign<T>
where T: FloatCore + Zero,

Source§

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,

Source§

fn deserialize<D>( deserializer: D, ) -> Result<PositiveSign<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Display for PositiveSign<T>
where T: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<PositiveSign<f32>> for NotNan<f32>

Source§

fn from(value: PositiveSign<f32>) -> NotNan<f32>

Converts to this type from the input type.
Source§

impl From<PositiveSign<f64>> for NotNan<f64>

Source§

fn from(value: PositiveSign<f64>) -> NotNan<f64>

Converts to this type from the input type.
Source§

impl From<ZeroOne<f32>> for PositiveSign<f32>

Source§

fn from(value: ZeroOne<f32>) -> PositiveSign<f32>

Converts to this type from the input type.
Source§

impl From<ZeroOne<f64>> for PositiveSign<f64>

Source§

fn from(value: ZeroOne<f64>) -> PositiveSign<f64>

Converts to this type from the input type.
Source§

impl From<bool> for PositiveSign<f32>

Source§

fn from(value: bool) -> PositiveSign<f32>

Converts to this type from the input type.
Source§

impl From<bool> for PositiveSign<f64>

Source§

fn from(value: bool) -> PositiveSign<f64>

Converts to this type from the input type.
Source§

impl From<u16> for PositiveSign<f32>

Source§

fn from(value: u16) -> PositiveSign<f32>

Converts to this type from the input type.
Source§

impl From<u16> for PositiveSign<f64>

Source§

fn from(value: u16) -> PositiveSign<f64>

Converts to this type from the input type.
Source§

impl From<u32> for PositiveSign<f64>

Source§

fn from(value: u32) -> PositiveSign<f64>

Converts to this type from the input type.
Source§

impl From<u8> for PositiveSign<f32>

Source§

fn from(value: u8) -> PositiveSign<f32>

Converts to this type from the input type.
Source§

impl From<u8> for PositiveSign<f64>

Source§

fn from(value: u8) -> PositiveSign<f64>

Converts to this type from the input type.
Source§

impl<T> Hash for PositiveSign<T>
where T: PrimitiveFloat,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Mul<PositiveSign<T>> for ZeroOne<T>
where T: FloatCore, PositiveSign<T>: From<ZeroOne<T>>,

Source§

type Output = PositiveSign<T>

The resulting type after applying the * operator.
Source§

fn mul( self, rhs: PositiveSign<T>, ) -> <ZeroOne<T> as Mul<PositiveSign<T>>>::Output

Performs the * operation. Read more
Source§

impl Mul<PositiveSign<f32>> for Rgb

Multiplies this color value by a scalar.

Source§

fn mul(self, scalar: PositiveSign<f32>) -> Rgb

Multiplies this color value by a scalar.

Source§

type Output = Rgb

The resulting type after applying the * operator.
Source§

impl<T> Mul<ZeroOne<T>> for PositiveSign<T>
where T: FloatCore, PositiveSign<T>: From<ZeroOne<T>>,

Source§

type Output = PositiveSign<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: ZeroOne<T>) -> <PositiveSign<T> as Mul<ZeroOne<T>>>::Output

Performs the * operation. Read more
Source§

impl<T> Mul for PositiveSign<T>
where T: FloatCore<Output = T> + Mul,

Source§

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>

The resulting type after applying the * operator.
Source§

impl<T> MulAssign for PositiveSign<T>
where T: FloatCore<Output = T> + Mul,

Source§

fn mul_assign(&mut self, rhs: PositiveSign<T>)

Performs the *= operation. Read more
Source§

impl<T> One for PositiveSign<T>
where T: FloatCore + One,

Source§

fn one() -> PositiveSign<T>

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<T> Ord for PositiveSign<T>
where T: FloatCore + PartialOrd,

Source§

fn cmp(&self, other: &PositiveSign<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq<T> for PositiveSign<T>
where T: PartialEq,

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq for PositiveSign<T>
where T: PartialEq,

Source§

fn eq(&self, other: &PositiveSign<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd<T> for PositiveSign<T>
where T: PartialOrd,

Source§

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 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> PartialOrd for PositiveSign<T>
where T: FloatCore + PartialOrd,

Source§

fn partial_cmp(&self, other: &PositiveSign<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Sum for PositiveSign<T>
where T: FloatCore + Sum, PositiveSign<T>: TryFrom<T>,

Source§

fn sum<I>(iter: I) -> PositiveSign<T>
where I: Iterator<Item = PositiveSign<T>>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T> TryFrom<NotNan<T>> for PositiveSign<T>
where PositiveSign<T>: TryFrom<T, Error = NotPositiveSign<T>>,

Source§

fn try_from( value: NotNan<T>, ) -> Result<PositiveSign<T>, <PositiveSign<T> as TryFrom<NotNan<T>>>::Error>

Checks that value is non-negative.

  • If value is positive (including positive infinity), returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is negative non-zero or NaN, returns an error.
Source§

type Error = NotPositiveSign<T>

The type returned in the event of a conversion error.
Source§

impl TryFrom<f32> for PositiveSign<f32>

Source§

fn try_from( value: f32, ) -> Result<PositiveSign<f32>, <PositiveSign<f32> as TryFrom<f32>>::Error>

Checks that value is non-negative and non-NaN.

  • If value is positive (including positive infinity), returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is negative non-zero or NaN, returns an error.
Source§

type Error = NotPositiveSign<f32>

The type returned in the event of a conversion error.
Source§

impl TryFrom<f64> for PositiveSign<f64>

Source§

fn try_from( value: f64, ) -> Result<PositiveSign<f64>, <PositiveSign<f64> as TryFrom<f64>>::Error>

Checks that value is non-negative and non-NaN.

  • If value is positive (including positive infinity), returns wrapped value.
  • If value is zero of either sign, returns wrapped positive zero. This is lossy, but corresponds to the IEEE 754 idea that -0.0 == +0.0.
  • If value is negative non-zero or NaN, returns an error.
Source§

type Error = NotPositiveSign<f64>

The type returned in the event of a conversion error.
Source§

impl<T> Zero for PositiveSign<T>
where T: FloatCore + Zero,

Source§

fn zero() -> PositiveSign<T>

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<T> Copy for PositiveSign<T>
where T: Copy,

Source§

impl<T> Eq for PositiveSign<T>
where T: PartialEq,

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts the type to dyn Any.
Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<T> DynHash for T
where T: DynEq + Hash,

Source§

fn as_dyn_eq(&self) -> &(dyn DynEq + 'static)

Casts the type to dyn Any.
Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> One for T
where T: One,

Source§

fn one() -> T

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> Zero for T
where T: Zero,

Source§

fn zero() -> T

Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,