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.

Wrongly evaluated equality comparison

See original GitHub issue

Reporting 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:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sklamcommented, Oct 25, 2021

Yes, it does cover it, but I’ll add a link to reference the reproducer in #7480.

0reactions
esccommented, Oct 14, 2021

Thanks a lot for the quick fix!

Is the related comparison issue I mentioned covered by #7480 or should I report it separately (or is it working as expected in the first place 😉)?

I think it is covered. @sklam do you agree?

Read more comments on GitHub >

github_iconTop 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 >

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