Trait NumberBase

Source
pub trait NumberBase:
    Clone
    + Eq
    + Hash
    + PartialOrd {
    // Required methods
    fn zero() -> Self;
    fn one() -> Self;
    fn nan() -> Self;
    fn add(&self, rhs: &Self) -> Self;
    fn sub(&self, rhs: &Self) -> Self;
    fn mul(&self, rhs: &Self) -> Self;
    fn div(&self, rhs: &Self) -> Self;

    // Provided methods
    fn is_zero(&self) -> bool { ... }
    fn is_one(&self) -> bool { ... }
    fn is_nan(&self) -> bool { ... }
}
Expand description

Basic trait for numbers

zero(), one(), and nan() are implemented as functions because depending on the number underlying type, it can be hard/impossible to obtain a const for these values. This trait also includes basic arithmetic methods. This is to avoid cloning of big integers. We could also require &Self: Add<&Self, Output = Self> etc., but this would lead to ugly trait bounds.

Used by PseudoBooleanFunction::Number

Required Methods§

Source

fn zero() -> Self

Get the value 0

Source

fn one() -> Self

Get the value 1

Source

fn nan() -> Self

Get the value “not a number,” e.g. the result of a division 0/0.

Self::nan() == Self::nan() should evaluate to true.

Source

fn add(&self, rhs: &Self) -> Self

Compute self + rhs

Source

fn sub(&self, rhs: &Self) -> Self

Compute self - rhs

Source

fn mul(&self, rhs: &Self) -> Self

Compute self * rhs

Source

fn div(&self, rhs: &Self) -> Self

Compute self / rhs

Provided Methods§

Source

fn is_zero(&self) -> bool

Returns true iff self == Self::zero()

Source

fn is_one(&self) -> bool

Returns true iff self == Self::one()

Source

fn is_nan(&self) -> bool

Returns true iff self == Self::nan()

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§