Skip to content

Add float_compare_mode for comparing floats with epsilon#34

Open
JonathanMurray wants to merge 1 commit intodavidpdrsn:mainfrom
JonathanMurray:master
Open

Add float_compare_mode for comparing floats with epsilon#34
JonathanMurray wants to merge 1 commit intodavidpdrsn:mainfrom
JonathanMurray:master

Conversation

@JonathanMurray
Copy link

@JonathanMurray JonathanMurray commented Jun 27, 2023

Solves #29

@JonathanMurray
Copy link
Author

Hi! I have some test-cases that need to account for small differences in floating point values. The need is very similar to what's suggested in #29, so I took a stab at implementing it here.

I started out with the less verbose syntax .float_eq_epsilon(0.001), but changed it to an enum midway to try to maintain more consistency with the existing options, and make it easier to document the two cases (what happens if you specify an epsilon, and what happens if you don't). If we prefer the more concise version, that's easy to change though.

Does the approach look sensible, or am I missing some nuance?

Oh, I also had to pull in an extra dependency. Seemed reasonable to me, not trying to implement the float comparisons by hand, although it pained me to grow the list of dependencies from 2 to 3 😄

@JonathanMurray
Copy link
Author

@davidpdrsn Does this implementation look reasonable to you?

B-2U added a commit to B-2U/assert-json-same that referenced this pull request May 29, 2025
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.

1 participant