Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix some edge cases for compile time operations of % operator #1566

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

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

faze-geek
Copy link
Contributor

@faze-geek faze-geek commented Mar 7, 2023

Fixes #1562
On master -

def f():
    print((8)%3)
    print((8)%-3)         
    print((-8)%3)
    print((8.0)%3.0)
    print((8.0)%-3.0)         
    print((-8.0)%3.0)            
    
f()

(lp) C:\Users\kunni\lpython>python try.py
2
-1
1
2.0
-1.0
1.0

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
2
2
-2
2.00000000000000000e+00
2.00000000000000000e+00
-2.00000000000000000e+00

On branch -

def f():
    print((8)%3)
    print((8)%-3)         
    print((-8)%3)
    print((8.0)%3.0)
    print((8.0)%-3.0)         
    print((-8.0)%3.0)            
    
f()

(lp) C:\Users\kunni\lpython>python try.py
2
-1
1
2.0
-1.0
1.0

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
2
-1
1
2.00000000000000000e+00
-1.00000000000000000e+00
1.00000000000000000e+00

@faze-geek
Copy link
Contributor Author

On master -

def f():
    print(8%0)
    
f()

(lp) C:\Users\kunni\lpython>python try.py
Traceback (most recent call last):
ZeroDivisionError: integer division or modulo by zero

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
Floating point exception

On branch -

def f():
    print((8)%0)
    
f()
(lp) C:\Users\kunni\lpython>python try.py
Traceback (most recent call last):
ZeroDivisionError: integer division or modulo by zero

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
semantic error: Integer division or modulo by zero
 --> try.py:2:11
  |
2 |     print((8)%0)
  |           ^^^^^

@czgdp1807 czgdp1807 marked this pull request as draft March 7, 2023 17:44
@faze-geek faze-geek requested a review from czgdp1807 March 10, 2023 04:08
@faze-geek
Copy link
Contributor Author

@czgdp1807 is the latest commit regarding comments fine ?

@czgdp1807 czgdp1807 marked this pull request as ready for review March 11, 2023 06:47
@czgdp1807
Copy link
Collaborator

Please mark your PR ready for review whenever you feel its ready.

Copy link
Collaborator

@czgdp1807 czgdp1807 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the tests for it as well.

@czgdp1807 czgdp1807 marked this pull request as draft March 11, 2023 06:50
@faze-geek
Copy link
Contributor Author

@Thirumalai-Shaktivel . Could you help me to resolve the conflicts here. Locally I didn't get any conflicts, neither did python run_tests.py fail after updating them, so I'm not sure how to handle it.

@faze-geek faze-geek marked this pull request as ready for review March 12, 2023 06:45
@czgdp1807
Copy link
Collaborator

You simply had to,

  1. Update your main branch locally from https://github.com/lcompilers/lpython
  2. Checkout into mod.
  3. Execute git merge main. It will show CONFLICTs in the output on your terminal/command line.
  4. Do git add . for safety.
  5. Do a clean build.
  6. Update reference tests via, python run_tests.py -u.
  7. Do git add . and git commit -m "your_message".
  8. Push changes here.

@czgdp1807 czgdp1807 marked this pull request as draft March 15, 2023 04:43
@faze-geek
Copy link
Contributor Author

You simply had to,

  1. Update your main branch locally from https://github.com/lcompilers/lpython
  2. Checkout into mod.
  3. Execute git merge main. It will show CONFLICTs in the output on your terminal/command line.
  4. Do git add . for safety.
  5. Do a clean build.
  6. Update reference tests via, python run_tests.py -u.
  7. Do git add . and git commit -m "your_message".
  8. Push changes here.

Thanks, I'll keep this in mind. My apologies on using reset --hard on this instance as it manipulates the git history.

@faze-geek
Copy link
Contributor Author

This pull request is now ready for review.

@faze-geek faze-geek marked this pull request as ready for review March 16, 2023 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

% operator gives incorrect results compared to Cpython
3 participants