Skip to main content

Sign

Enum Sign 

Source
#[repr(i8)]
pub enum Sign { Negative = -1, Zero = 0, Positive = 1, }
Expand description

The sign of a real quantity.

The discriminants are -1, 0 and 1, so sign as i8 (or i8::from(sign)) gives the usual integer sign, and signs are ordered as those integers: Negative < Zero < Positive.

§Examples

use implicit_predicates_core::Sign;

assert_eq!(Sign::Negative as i8, -1);
assert_eq!(Sign::Zero as i8, 0);
assert_eq!(Sign::Positive as i8, 1);
assert!(Sign::Negative < Sign::Zero && Sign::Zero < Sign::Positive);

Variants§

§

Negative = -1

Strictly less than zero.

§

Zero = 0

Exactly zero.

§

Positive = 1

Strictly greater than zero.

Implementations§

Source§

impl Sign

Source

pub fn of(x: f64) -> Sign

Returns the sign of x. Both 0.0 and -0.0 give Sign::Zero.

NaN is not a valid input: debug builds panic on it, and release builds return Sign::Zero, which is meaningless.

§Examples
use implicit_predicates_core::Sign;

assert_eq!(Sign::of(2.5), Sign::Positive);
assert_eq!(Sign::of(-2.5), Sign::Negative);
assert_eq!(Sign::of(-0.0), Sign::Zero);
Source

pub fn is_zero(self) -> bool

Returns true if the sign is Sign::Zero.

§Examples
use implicit_predicates_core::Sign;

assert!(Sign::Zero.is_zero());
assert!(!Sign::Positive.is_zero());
Source

pub fn is_positive(self) -> bool

Returns true if the sign is Sign::Positive.

§Examples
use implicit_predicates_core::Sign;

assert!(Sign::Positive.is_positive());
assert!(!Sign::Zero.is_positive());
Source

pub fn is_negative(self) -> bool

Returns true if the sign is Sign::Negative.

§Examples
use implicit_predicates_core::Sign;

assert!(Sign::Negative.is_negative());
assert!(!Sign::Zero.is_negative());

Trait Implementations§

Source§

impl Clone for Sign

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Sign

Source§

impl Debug for Sign

Source§

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

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

impl Eq for Sign

Source§

impl From<Ordering> for Sign

Source§

fn from(ordering: Ordering) -> Sign

The sign of a - b when a.cmp(&b) is ordering: Less is negative, Equal zero and Greater positive.

§Examples
use implicit_predicates_core::Sign;

assert_eq!(Sign::from(3.cmp(&5)), Sign::Negative);
assert_eq!(Sign::from(5.cmp(&5)), Sign::Zero);
Source§

impl From<Sign> for i8

Source§

fn from(sign: Sign) -> i8

The integer sign: -1, 0 or 1.

§Examples
use implicit_predicates_core::Sign;

assert_eq!(i8::from(Sign::Negative), -1);
assert_eq!(i8::from(Sign::Positive), 1);
Source§

impl Hash for Sign

Source§

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

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 Mul for Sign

Source§

fn mul(self, rhs: Sign) -> Sign

The sign of a product: zero if either factor is zero, positive if the signs agree, negative otherwise.

§Examples
use implicit_predicates_core::Sign;

assert_eq!(Sign::Negative * Sign::Negative, Sign::Positive);
assert_eq!(Sign::Negative * Sign::Positive, Sign::Negative);
assert_eq!(Sign::Zero * Sign::Positive, Sign::Zero);
Source§

type Output = Sign

The resulting type after applying the * operator.
Source§

impl Neg for Sign

Source§

fn neg(self) -> Sign

Flips the sign; Sign::Zero stays zero.

§Examples
use implicit_predicates_core::Sign;

assert_eq!(-Sign::Positive, Sign::Negative);
assert_eq!(-Sign::Zero, Sign::Zero);
Source§

type Output = Sign

The resulting type after applying the - operator.
Source§

impl Ord for Sign

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Sign

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Sign

Source§

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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for Sign

Auto Trait Implementations§

§

impl Forget for Sign

§

impl Freeze for Sign

§

impl Move for Sign

§

impl RefUnwindSafe for Sign

§

impl Send for Sign

§

impl Sync for Sign

§

impl Unpin for Sign

§

impl UnsafeUnpin for Sign

§

impl UnwindSafe for Sign

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> 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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.