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

Aggressive typecasting with specialization leads to silent wrong value output #9506

Open
2 tasks done
ZzEeKkAa opened this issue Mar 20, 2024 · 1 comment
Open
2 tasks done
Labels
bug - incorrect behavior Bugs: incorrect behavior bug - numerically incorrect Bugs: numerical behaviour is incorrect

Comments

@ZzEeKkAa
Copy link

ZzEeKkAa commented Mar 20, 2024

Reporting a bug

Following code implicitly type cast float64 to int32, so the data after dot is getting lost.

import numba
from numba import int32


@numba.njit(int32(int32))
def inc(a):
    return a+1

if __name__ == "__main__":
    b = 1.5
    b1 = inc(b) # <- does not raise exception
    assert b1 == 2.5 # actual value is 2, because float(1.5) was cast to int32. 

Instead I would expect to see exception based on the https://en.cppreference.com/w/cpp/language/implicit_conversion . It may be either exception, either warning, but never silent loss of data.

@kc611 kc611 added bug - incorrect behavior Bugs: incorrect behavior bug - numerically incorrect Bugs: numerical behaviour is incorrect labels Mar 21, 2024
@kc611
Copy link
Collaborator

kc611 commented Mar 21, 2024

Hi @ZzEeKkAa , Thanks for reporting this bug. I can reproduce the issue locally.

This does seem like a case of implicit unsafe casting behaviour that would need to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - incorrect behavior Bugs: incorrect behavior bug - numerically incorrect Bugs: numerical behaviour is incorrect
Projects
None yet
Development

No branches or pull requests

2 participants