Expand description
Provides utility functions for working with floating point precision.
This module is intended for internal use within the statrs crate to ensure consistent
precision checking across all statistical computations. While it is currently public
for historical reasons, it will be made private in a future breaking release.
§Usage
The module provides three main types of precision checks:
-
Absolute difference checks (
abs_diff_eq!) - Use when comparing values that should be close in absolute terms, e.g., when checking if a value is close to zero -
Relative difference checks (
relative_eq!) - Use when comparing values that scale with the input, e.g., when comparing probability densities or statistical moments -
ULPs (Units in Last Place) checks (
ulps_eq!) - Use for comparing values that should be close in terms of floating-point representation
Each check type has both a non-asserting version (e.g., abs_diff_eq!) and an
asserting version (e.g., assert_abs_diff_eq!).
§Default Precision Levels
The module defines default precision levels that are carefully chosen to balance correctness and performance:
DEFAULT_RELATIVE_ACC: 1e-14 for relative comparisonsDEFAULT_EPS: 1e-9 for absolute comparisonsDEFAULT_ULPS: 5 for ULPs comparisons
These defaults should be used unless there is a specific reason to use different precision levels.
§Module-Specific Precision
Some modules may require different precision levels than the crate defaults. In such
cases, the module should define its own precision constants using the same names as
defined here (e.g., MODULE_RELATIVE_ACC, MODULE_EPS) to maintain consistency
and searchability.
§Deprecated Functionality
The following items are deprecated and will be removed in a future release:
almost_eqfunction - Useabs_diff_eq!macro insteadassert_almost_eq!macro - Useassert_abs_diff_eq!macro instead
Constants§
- DEFAULT_
EPS - Default and target absolute accuracy for f64 operations
- DEFAULT_
F64_ ACC - Default accuracy for
f64, equivalent to0.0 * F64_PREC - DEFAULT_
RELATIVE_ ACC - Default and target relative accuracy for f64 operations
- DEFAULT_
ULPS - Default and target ULPs accuracy for f64 operations
- F64_
PREC - Standard epsilon, maximum relative precision of IEEE 754 double-precision
floating point numbers (64 bit) e.g.
2^-53
Functions§
- almost_
eq Deprecated - Compares if two floats are close via
approx::abs_diff_equsing a maximum absolute difference (epsilon) ofacc.