Skip to main content

Crate use_numerical

Crate use_numerical 

Source
Expand description

§use-numerical

Small approximate numerical helpers for RustUse.
Focused helpers for floating-point comparison, finite differences, numerical integration, and iterative root finding.

Rust 1.95.0+ Edition 2024 Approximate numerical methods License MIT or Apache-2.0

§Install

[dependencies]
use-numerical = "0.0.6"

Optional bounded-interval bridge support:

[dependencies]
use-numerical = { version = "0.0.6", features = ["interval"] }

§What belongs here

use-numerical owns small, explicit helpers for approximate numerical work over f64. It provides:

  • tolerance-based floating-point comparison
  • first-derivative finite difference helpers
  • deterministic numerical integration rules
  • iterative root-finding helpers and error types

This crate is intentionally about approximation-oriented methods only. It does not add exact algebraic solvers, symbolic differentiation, symbolic integration, polynomial-specific APIs, matrix solving, or optimization workflows.

§Neighboring crates

CrateResponsibility
use-numericalApproximate numerical methods, tolerances, and iterative solvers
use-equationExact small equation helpers such as linear and quadratic formulas
use-polynomialPolynomial structs, evaluation, derivatives, and direct operations
use-calculusCalculus concepts and higher-level derivative or integral workflows
use-optimizationOptimization algorithms and optimization workflows
use-realReal-number abstractions and validation policy
use-linearMatrix and vector driven linear-system solving

§Examples

§Compare floating-point values with an epsilon

use use_numerical::approx_eq;

assert!(approx_eq(0.1 + 0.2, 0.3, 1e-12));

§Approximate a derivative with a central difference

use use_numerical::central_difference;

let derivative = central_difference(|x| x * x, 3.0, 1e-6);

assert!((derivative - 6.0).abs() < 1e-5);

§Integrate numerically with the trapezoidal rule

use use_numerical::trapezoidal_rule;

let area = trapezoidal_rule(|x| x * x, 0.0, 1.0, 1_000).unwrap();

assert!((area - 1.0 / 3.0).abs() < 1e-3);

§Find a root with bisection

use use_numerical::{RootOptions, bisection};

let root = bisection(
    |x| x * x - 2.0,
    1.0,
    2.0,
    RootOptions::default(),
)
.unwrap();

assert!((root - 2.0_f64.sqrt()).abs() < 1e-8);

§Find a root with Newton-Raphson

use use_numerical::{RootOptions, newton_raphson};

let root = newton_raphson(
    |x| x * x - 2.0,
    |x| 2.0 * x,
    1.0,
    RootOptions::default(),
)
.unwrap();

assert!((root - 2.0_f64.sqrt()).abs() < 1e-8);

§Status

use-numerical is a concrete pre-1.0 crate in the RustUse math workspace. It keeps approximation helpers explicit and reusable so neighboring calculus, equation, polynomial, simulation, control, signal, optimization, and physics crates can build on one small numerical surface. Small approximate numerical helpers for RustUse.

Modules§

approx
Floating-point comparison helpers for approximate numerical work.
difference
Finite-difference helpers for first-derivative approximation.
integration
Deterministic numerical integration rules over f64 intervals.
root
Iterative approximate root-finding helpers.

Structs§

RootOptions
Configuration for iterative approximate root finders.

Enums§

RootError
Failure modes for approximate iterative root finders.

Functions§

approx_eq
Returns true when a and b are within an absolute epsilon.
backward_difference
Approximates the first derivative with a backward difference.
bisection
Finds a root with the bisection method on a bracketing interval.
bisection_interval
Finds a root with the bisection method over a bounded use-interval interval.
central_difference
Approximates the first derivative with a central difference.
clamp_epsilon
Normalizes an epsilon to a non-negative finite value.
forward_difference
Approximates the first derivative with a forward difference.
midpoint_rule
Approximates an integral with the midpoint rule.
newton_raphson
Finds a root with Newton-Raphson iteration.
rectangle_rule
Approximates an integral with the left-rectangle rule.
relative_eq
Returns true when a and b are within a relative epsilon.
simpsons_rule
Approximates an integral with Simpson’s rule.
trapezoidal_rule
Approximates an integral with the trapezoidal rule.