Trait oxidd_core::function::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()

Object Safety§

This trait is not object safe.

Implementors§