Trait Arith

Source
pub trait Arith: Clone {
    // Required methods
    fn from_f64(value: f64) -> Self;
    fn from_dyadic(value: &Dyadic) -> Self;
    fn add(&self, other: &Self) -> Self;
    fn sub(&self, other: &Self) -> Self;
    fn mul(&self, other: &Self) -> Self;
    fn neg(&self) -> Self;
    fn sign(&self) -> Option<Sign>;

    // Provided methods
    fn sqrt_enclosure(&self) -> Option<Self> { ... }
    fn square(&self) -> Self { ... }
}
Expand description

A number system an expression can be evaluated in.

Implemented by crate::Interval (fast, may be undecided) and crate::Dyadic (exact, always decided). Writing an expression once, generically, is what guarantees the filter and the exact fallback evaluate the same polynomial.

Required Methods§

Source

fn from_f64(value: f64) -> Self

The value of a finite f64.

Callers must pass finite values; check with crate::require_finite. Non-finite input is never silently accepted: the interval tier widens it to the whole line and the exact tier panics.

Source

fn from_dyadic(value: &Dyadic) -> Self

The value of an exact dyadic number: itself in the exact tier, a sound enclosure in the interval tier (Dyadic::enclosure).

Lets exact intermediate data (a constructed point, a normalised coefficient) enter an expression that is then evaluated in both tiers, so the filter still runs first.

Source

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

self + other.

Source

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

self - other.

Source

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

self * other.

Source

fn neg(&self) -> Self

-self.

Source

fn sign(&self) -> Option<Sign>

The sign, or None when this arithmetic cannot decide it.

Exact arithmetics always return Some.

Provided Methods§

Source

fn sqrt_enclosure(&self) -> Option<Self>

An enclosure of sqrt(self), for approximate arithmetics only.

The interval tier uses it to evaluate nested radicals numerically, which decides far more signs than case analysis on coefficients (a coefficient that is exactly zero becomes an interval straddling zero, and case analysis stops there). Exact arithmetics return None: they decide by case analysis instead, never by a rounded root. Also None whenever self might be negative, so a filter never assigns a sign to a value that is not real.

Source

fn square(&self) -> Self

self * self.

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§