Skip to main content

Crate arithmetica

Crate arithmetica 

Source
Expand description

Exact geometric predicates for f64 input.

orient2d, incircle, orient3d and insphere return the sign of their determinant exactly, for every finite input: any magnitudes, subnormals and exactly degenerate configurations included. A NaN or infinite coordinate returns NonFinite rather than a plausible-looking Sign.

use arithmetica::{Sign, orient2d};

assert_eq!(orient2d([0.0, 0.0], [1.0, 0.0], [0.0, 1.0]), Ok(Sign::Positive));
assert_eq!(orient2d([0.0, 0.0], [1.0, 1.0], [2.0, 2.0]), Ok(Sign::Zero));
assert!(orient2d([f64::NAN, 0.0], [1.0, 0.0], [0.0, 1.0]).is_err());

§Contents

§How the predicates stay exact

Each predicate is a ladder of stages, and each stage either certifies a sign or passes the input on:

  1. a filter in native f64 with the underflow-protected error bound of Bartels, Fisikopoulos and Weiser (2023), valid for every finite input;
  2. Shewchuk’s adaptive expansion stages, run only inside an exactness window of magnitudes where binary64 provably behaves as his unbounded-exponent model, with input moved there by an exact power-of-two rescale when possible;
  3. exact fixed-width integer arithmetic for everything else.

The README and docs/exactness_window.md in the repository give the full argument and the references.

Re-exports§

pub use rational::RationalCoord2d;
pub use rational::orient2d_rational;
pub use rational::rational_compare_along;
pub use rational::rational_coords_equal;

Modules§

counters
Optional counters recording how often each predicate reaches its exact fallback.
expansion
Low-level floating-point expansion arithmetic primitives.
rational
Exact predicates over constructed points.

Structs§

F64Bracket
The two representable f64 values that bracket an exact value, and the value’s exact position between them.
NonFinite
Error returned by a geometric predicate when an input coordinate is not finite (NaN, +∞, or −∞).

Enums§

BracketPosition
Where an exact value sits relative to its two nearest representable f64 neighbors.
Sign
All predicates in this crate return Sign rather than f64 or bool. The three variants correspond to the three mathematically distinct outcomes of a predicate determinant.

Functions§

incircle
Tests whether point pd lies inside the circumcircle of triangle pa, pb, pc.
insphere
Tests whether pe lies inside the circumsphere of pa, pb, pc, pd.
orient2d
Tests the orientation of the triangle formed by pa, pb, and pc.
orient3d
Tests the orientation of the tetrahedron formed by four 3D points.