{ } JustinGeoSci

Arithmetica User Guide

Arithmetica is a Rust crate of exact geometric predicates and constructions for f64 input.

Overview

Arithmetica answers the sign questions on which computational geometry is built, such as which side of a line a point lies on or whether a point lies inside a circle, and it returns the exact answer for every finite f64 input. That answer is the sign of the true determinant, for any magnitudes, subnormals and near-degenerate configurations included, rather than an answer that is right only for typical input.

The four classical predicates, orient2d, incircle, orient3d and insphere, follow Shewchuk’s adaptive-precision design, and the crate extends that design in three ways. An exact integer stage completes every predicate, so the guarantee holds over the whole binary64 range rather than only where no operation overflows or underflows. The same sequence of stages decides four further sign questions, the comparison of distances and the sign of an angle. Exact rational constructions represent the intersection of two lines without rounding and compare such points exactly.

The guide has six parts:

The crate is #![no_std], allocates nothing, has no runtime dependencies, and forbids unsafe code. No input causes a panic.

Conventions

A few conventions hold throughout the crate.

  • Points are plain arrays: [f64; 2] in 2D and [f64; 3] in 3D.
  • Results. Every predicate returns Result<Sign, NonFinite>. Sign is Positive, Negative or Zero, and it is the sign of the exact quantity rather than an estimate of it.
  • Zero is an answer rather than a failure. It means the configuration is exactly degenerate: collinear, cocircular, coplanar, cospherical, equidistant, a right angle, or a point at exactly the given distance. Code that treats it as either of the other two signs has a bug.
  • Orientation. orient2d is Positive for a counterclockwise triple, with the y-axis pointing up. Every other predicate’s convention is stated on its own entry.
  • Non-finite input. A NaN or infinite coordinate returns Err(NonFinite), never a sign.
  • Arithmetic. The proofs assume IEEE 754 binary64 with round-to-nearest-even and no extended precision. Every x86-64 target satisfies this through SSE2, and the x87 FPU in 80-bit mode does not.
  • Examples are short Rust programs whose results are shown with assert_eq!. Every example in this guide is compiled and run against the published crate.

Citation

If you use arithmetica in academic work, please cite the software and the two papers whose methods it implements. The DOI below always resolves to the latest version.

Erlick, J. (2026). arithmetica (Version 0.1.1) [Computer software]. https://doi.org/10.5281/zenodo.23307342

Installation

Requirements

  • Rust 1.85 or later, edition 2024
  • No runtime dependencies. The crate works in #![no_std] crates and without an allocator.

From crates.io

cargo add arithmetica

or add it to Cargo.toml directly:

[dependencies]
arithmetica = "0.1"

Cargo features

Feature Default Effect
stage-counters off Records, per predicate, how many calls each stage answered (see Stage counters). With the feature off the counters compile to nothing. It counts the four classical predicates, and the four distance and angle predicates are not counted in 0.1.
fuzz-replay off Compiles nothing. It remains so that a build naming it, as 0.1.0 allowed, still resolves, and it will be removed in 0.2.
cargo add arithmetica --features stage-counters

From source

git clone https://github.com/JustinGeoSci/arithmetica.git
cd arithmetica

cargo build
cargo test

API reference documentation for every release is published on docs.rs.

Quick start

Classify the orientation of three points, test a point against a circle, compare two distances, and see a non-finite coordinate rejected:

use arithmetica::{Sign, compare_distance, incircle, orient2d};

// Counterclockwise, clockwise and collinear triples.
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], [0.0, 1.0], [1.0, 0.0]), Ok(Sign::Negative));
assert_eq!(orient2d([0.0, 0.0], [1.0, 1.0], [2.0, 2.0]), Ok(Sign::Zero));

// Is (1, 1) inside the circle through (0, 0), (2, 0) and (0, 2)?
assert_eq!(
    incircle([0.0, 0.0], [2.0, 0.0], [0.0, 2.0], [1.0, 1.0]),
    Ok(Sign::Positive)
);

// (3, 4) and (5, 0) are exactly equidistant from the origin.
assert_eq!(compare_distance([0.0, 0.0], [3.0, 4.0], [5.0, 0.0]), Ok(Sign::Zero));

// A NaN or infinite coordinate is an error, never a plausible-looking sign.
assert!(orient2d([f64::NAN, 0.0], [1.0, 0.0], [0.0, 1.0]).is_err());

Geometric predicates and Distance and angle predicates list the full set, and the numerical model explains why every answer is exact.