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 the crate float-cmp #3338

Merged
merged 1 commit into from
Oct 25, 2024
Merged

Remove the crate float-cmp #3338

merged 1 commit into from
Oct 25, 2024

Conversation

jcamiel
Copy link
Collaborator

@jcamiel jcamiel commented Oct 25, 2024

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 crate

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 already 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 linked an issue Oct 25, 2024 that may be closed by this pull request
@fabricereix
Copy link
Collaborator

/accept

@hurl-bot
Copy link
Collaborator

🕗 /accept is running, please wait for completion.

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

```rust
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 https://github.com/Orange-OpenSource/hurl/blob/07512a9cbfbba17cd16df3706f3a0c5c98b67d3d/packages/hurl/src/runner/number.rs#L32-L40
so there is no reason to use `float-cmp` in jsonpath module
@hurl-bot
Copy link
Collaborator

🔨 Auto rebase from Orange-OpenSource/hurl/master succeeds, Orange-OpenSource/hurl/3247-remove-float-cmp-crate now embeds these commits:

@hurl-bot
Copy link
Collaborator

🕗 /accept is still running, please wait for completion.

@hurl-bot
Copy link
Collaborator

✅ Pull request merged and closed by fabricereix with fast forward merge..

# List of commits merged from Orange-OpenSource/hurl/3247-remove-float-cmp-crate branch into Orange-OpenSource/hurl/master branch:

  • d5f1b3e Remove the crate float-cmp.

@hurl-bot hurl-bot merged commit d5f1b3e into master Oct 25, 2024
23 checks passed
@hurl-bot hurl-bot deleted the 3247-remove-float-cmp-crate branch October 25, 2024 07:30
@jcamiel jcamiel changed the title Remove the crate float-cmp. Remove the crate float-cmp Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove float-cmp crate
3 participants