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

Unsigned integers improvement and fixes #2108

Merged
merged 3 commits into from
Jul 5, 2023

Conversation

Shaikh-Ubaid
Copy link
Collaborator

@Shaikh-Ubaid Shaikh-Ubaid commented Jul 5, 2023

On main:

$ cat examples/expr2.py 
from lpython import u32, u64

def test():
    x : u32 = u32(-10)
    print(x)
    assert x == u32(4294967286)

    z: u64 = u64(x)
    print(z)
    assert z == u64(4294967286)

test()
$ python examples/expr2.py     
4294967286
4294967286
$ lpython examples/expr2.py
4294967286
18446744073709551606
AssertionError

On branch:

$ cat examples/expr2.py     
from lpython import u32, u64

def test():
    x : u32 = u32(-10)
    print(x)
    assert x == u32(4294967286)

    z: u64 = u64(x)
    print(z)
    assert z == u64(4294967286)

test()
$ python examples/expr2.py     
4294967286
4294967286
$ lpython examples/expr2.py
4294967286
4294967286

It seems negation internally uses 2's complement.

Refactor: LLVM: Combine visit_IntegerUnaryMinus() and visit_UnsignedIntegerUnaryMinus()
@Shaikh-Ubaid Shaikh-Ubaid requested a review from certik July 5, 2023 18:38
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

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

Thanks!

@certik certik merged commit de44dbf into lcompilers:main Jul 5, 2023
8 checks passed
@Shaikh-Ubaid Shaikh-Ubaid deleted the unsigned_ints_impr branch July 5, 2023 19:14
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.

2 participants