Skip to main content

cmp_epsilon

Function cmp_epsilon 

Source
pub fn cmp_epsilon(a: f64, b: f64, eps: f64) -> Ordering
Expand description

Three-way comparison of a and b with the relative tolerance eps: Ordering::Equal when |a - b| / (|a| + |b|) < eps, otherwise the natural order of the two numbers.

Infinities are equal to infinities of the same sign and are larger (or smaller) than every finite number, whatever the tolerance. NaN is never equal to anything (not even NaN), but the direction of the resulting ordering is unspecified. An eps of zero means exact comparison; negative values of eps give unspecified results.

Binds igraph_cmp_epsilon.

ยงExamples

use igraph::misc::cmp_epsilon;
use std::cmp::Ordering;

assert_eq!(cmp_epsilon(1.0, 1.0 + 1e-12, 1e-9), Ordering::Equal);
assert_eq!(cmp_epsilon(1.0, 2.0, 1e-9), Ordering::Less);
assert_eq!(cmp_epsilon(f64::INFINITY, 1e300, 0.5), Ordering::Greater);