Skip to main content

RealNum

Trait RealNum 

Source
pub trait RealNum:
    Real
    + Euclid
    + Debug { }
Expand description

A scalar field for use as the coordinate type of a Euclidean space.

Bundles the requirements that a scalar must satisfy to be usable throughout diffable — real arithmetic and debuggability.

§Note on equality

Mathematically the scalars model the real numbers, which have genuine equality. Computationally they do not: any finite representation that is also fast (f64, f32) cannot satisfy the field axioms exactly, and its PartialEq is therefore necessarily a tolerance relation — see R64/R32, which report equality up to a relative-or-absolute epsilon. Such a relation is reflexive and symmetric but not transitive: a == b and b == c do not imply a == c.

The library accommodates this rather than fighting it. Two consequences an implementor should know:

  • The check_* invariants never chain equalities. Every property test performs a single comparison between a computed value and an expected one; none relies on transitivity, so a tolerance-based PartialEq is sound to use with them. Do not add checks that compare a to b, then b to c, and infer a to c — that inference is invalid for the scalars this library is designed to run on.

  • Exact scalars get exact semantics for free. A symbolic real, an arbitrary-precision rational, or any type whose PartialEq is true equality satisfies everything above trivially (a transitive relation is in particular a non-chained one), and runs the same invariants with genuine equality. Approximation is a property of the scalar you choose, not an assumption baked into the trait hierarchy.

This is why equality is required only where it is actually exercised — in the #[cfg(feature = "testing")] invariants, via PartialEq bounds on those methods — and is deliberately not a structural bound on Point. Points have mathematical equality; the library declines to require a computable witness of it, because for the reals no faithful one exists.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<R: Real + Euclid + Debug> RealNum for R