Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove float-cmp crate #3247

Closed
jcamiel opened this issue Sep 20, 2024 · 0 comments · Fixed by #3338
Closed

Remove float-cmp crate #3247

jcamiel opened this issue Sep 20, 2024 · 0 comments · Fixed by #3338
Labels
enhancement New feature or request
Milestone

Comments

@jcamiel
Copy link
Collaborator

jcamiel commented Sep 20, 2024

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

@jcamiel jcamiel added the enhancement New feature or request label Sep 20, 2024
@jcamiel jcamiel added this to the 6.0.0 milestone Sep 20, 2024
@jcamiel jcamiel linked a pull request Oct 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant