-
Notifications
You must be signed in to change notification settings - Fork 171
Fix _mod function to fix the % operator results #1567
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
base: main
Are you sure you want to change the base?
Conversation
@@ -212,7 +212,7 @@ struct PythonIntrinsicProcedures { | |||
int64_t a = ASR::down_cast<ASR::IntegerConstant_t>(arg1)->m_n; | |||
int64_t b = ASR::down_cast<ASR::IntegerConstant_t>(arg2)->m_n; | |||
return ASR::down_cast<ASR::expr_t>( | |||
ASR::make_IntegerConstant_t(al, loc, a%b, type)); | |||
ASR::make_IntegerConstant_t(al, loc, ((a%b)+b)%b, type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I have handled the compile time evaluations in my pr #1566 and got reviews on it. Could you please remove it from here to avoid clashes.
Also _mod
function in lpython_builtin.py
works on runtime evaluations, something like this -
def f():
a:i32 = 8
b:i32 = -3
print(a%b)
f()
I hope you are aware of that, since all the test cases you refer in the OP are not in that format. Checkout if outputs of the print(a%b)
format are actually getting corrected by the changes you made in lpython_builtin.py
. On face value I can see that the below case is handled incorrectly -
def f():
a:i32 = 8
b:i32 = 0
print(a%b)
f()
(lp) C:\Users\kunni\lpython>python try.py
Traceback (most recent call last):
File "C:\Users\kunni\lpython\try.py", line 6, in <module>
f()
File "C:\Users\kunni\lpython\try.py", line 4, in f
print(a%b)
ZeroDivisionError: integer division or modulo by zero
(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
8
My bad I didn't see your PR, I removed it. However, thank you for letting me know about the format of the test case. The test case in the OP is the one used in #1562 so I was just trying to test against it again. I did some edits to handle the case mentioned in your comment:
I made
I got this:
I am not sure yet why it is behaving like this but I am looking into it. |
Yes, a bit strange. I got the same message on trying out your diff. @Thirumalai-Shaktivel I had pointed this out on zulip recently, Can you look into it !? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test in integration_tests
folder for this.
Closing 1562
Task List:
_lpython_floordiv
function in all the_mod
function with_floor
function I created based on themath.floor
function.On Branch: