Skip to main content

epsilon

Function epsilon 

Source
pub fn epsilon(precision: usize) -> OxiNumResult<DBig>
Expand description

Return the smallest positive “unit” representable at the requested decimal precision, i.e. 10^(1 - precision) rounded to precision significant digits.

In decimal base, a value with precision p has its least significant digit at position 10^(1 - p) when the leading digit is 1 — this is the “epsilon” in the floating-point sense.

precision == 0 is unlimited precision in dashu-float’s vocabulary; in that case there is no meaningful machine epsilon, so this helper returns an error.

§Errors

Returns OxiNumError::Precision if precision == 0.

§Examples

use std::str::FromStr;
use oxinum_float::{precision::epsilon, DBig};

let eps10 = epsilon(10).expect("precision 10");
// 10^(1 - 10) = 10^-9, at precision 10.
assert_eq!(eps10.precision(), 10);

let expected = DBig::from_str("1e-9")
    .expect("parse 1e-9")
    .with_precision(10)
    .value();
assert_eq!(eps10, expected);