Orange-OpenSource/hurl

Remove `float-cmp` crate

jcamiel opened this issue · 0 comments

float-cmp crate is used in one place in Hurl to check the comparison between two f64

approx_eq!(f64, v.as_f64().unwrap(), num.to_f64(), ulps = 2)

We can do a "classic" float comparison as clippy suggests https://rust-lang.github.io/rust-clippy/rust-1.72.0/index.html#/float_cmp and remove float-cmp from

let error_margin = f64::EPSILON; // Use an epsilon for comparison
// Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
// let error_margin = std::f64::EPSILON;
if (y - 1.23f64).abs() < error_margin { }
if (y - x).abs() > error_margin { }

Note: we compare f64 for predicate value here

impl PartialEq for Number {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Number::Float(v1), Number::Float(v2)) => (v1 - v2).abs() < f64::EPSILON,
(Number::Integer(v1), Number::Integer(v2)) => v1 == v2,
(Number::BigInteger(v1), Number::BigInteger(v2)) => v1 == v2,
_ => false,
}
}

so there is no reason to use float-cmp in jsonpath module