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

Skip to content

% operator gives incorrect results compared to Cpython #1562

@faze-geek

Description

@faze-geek

Got this while testing the % operator alongside math.mod in Lpython -

def f():
    print((8)%3)
    print((8)%(3))
    print(-(8)%3)          #wrong
    print((8)%-3)          #wrong
    print(-(8)%-3)
    print((-8)%3)          #wrong
    print(-8%3)            #wrong
    
f()

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions