Wrongly evaluated equality comparison
See original GitHub issueReporting a bug
- I have tried using the latest released version of Numba: yes, using version 0.54.1 (7 October, 2021)
- I have included a self contained code sample to reproduce the problem.
bug.py
from numba import njit
@njit
def func(x: float):
print("x:", x)
if x > 1:
action = "a"
elif x < -1:
action = "b"
else:
action = None
print("action:", action, action == "a", action == "b")
if action == "a":
print("performing action a")
elif action == "b":
print("performing action b")
func(1.2)
Output
x: 1.2
action: a False False
Apparently the condition action == "a" is wrongly evaluated.
Expected Output
This is the output when running with plain Python, i.e., removing @njit:
x: 1.2
action: a True False
performing action a
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
If statement - incorrect evaluation [duplicate] - Stack Overflow
1 Answer 1 · 2. A constant threshold value like 0.0001 may or may not be the best approach. · 1. This method...
Read more >1.2. Checking Equality or Comparing Values - O'Reilly
Use the equality (or inequality) or strict equality (or strict inequality) operator to compare two values. To check whether a value is a...
Read more >Comparing things to True the wrong way - QuantifiedCode
The statement below uses the equality operator to compare a boolean variable to True . This is not the PEP 8 preferred approach...
Read more >Why Does Excel Say Cell Values Are Not Equal When They ...
By incorporating the VALUE function in your test you can see (below) the test will successfully compare the two numbers as equal.
Read more >5.6 — Relational operators and floating point comparisons
Each of these operators evaluates to the boolean value true (1), or false (0). Here's some sample code using these operators with integers:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, it does cover it, but I’ll add a link to reference the reproducer in #7480.
I think it is covered. @sklam do you agree?