question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Equality tests on floats: add support for math.isclose() and numpy.isclose()

See original GitHub issue

Feature request

When testing the equality of two floating point numbers, it’s good practices to rely on approximations (e.g., abs(a - b) < epsilon) rather than on exact/bit-to-bit comparison.

In Python we can use math.isclose or numpy.isclose to do such tests. These functions are a bit different but both can be equally useful. Unlike the built-in math.isclose, numpy.isclose is not symmetric in a and b – it assumes b is the reference value – so that isclose(a, b) might be different from isclose(b, a).

  • Floating point comparison is a common enough operation so that Numba can support it (for both math and numpy libraries).
  • Moreover, all arguments of each function should be supported (relative tolerance, absolute tolerance, and equal_nan if existing) because each use case can have specific parameters.

I could not find an issue about that when searching issues with keywords “isclose”, “float comparison”, “float equality”.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
esccommented, Feb 5, 2021

@alexandrehuat It looks like no one is answering this question 😞 . If you would still like an answer, Rafia at codeFair knows Python and can help! Fill out this form if you’re interested: http://tinyurl.com/2uttspwt.

This comment appears to be spam since it is out of context and doesn’t make sense in the current conversation. My advice is: DO NOT CLICK THE LINK since it may very well redirect you to malware. I have reported the user @codeFairOfficial to the GitHub abuse program as outlined here: https://docs.github.com/en/github/building-a-strong-community/reporting-abuse-or-spam

0reactions
renatobellotticommented, Nov 9, 2022

I’d like to have this feature as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.isclose — NumPy v1.24 Manual
Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The ......
Read more >
PEP 485 – A Function for testing approximate equality
This PEP proposes the addition of an isclose() function to the standard library math module that determines whether one value is ...
Read more >
The Right Way to Compare Floats in Python - davidamos.dev
The trick is to avoid checking for equality. Never use == , >= , or <= with floats. Use the math.isclose() function instead:...
Read more >
What is the best way to compare floats for almost-equality in ...
Python 3.5 adds the math.isclose and cmath.isclose functions as described in PEP 485. If you're using an earlier version of Python, ...
Read more >
NumPy isclose Explained with examples in Python
The function NumPy isclose() does that for you. Also, it provides you with an option to add tolerant value, which comes very handy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found