← 输入框|github.com|刷新
Skip to content

Logical operation of two integers gives wrong answers. #1487

Closed

Description

@faze-geek

I haven't done a proper sleuthing before opening this issue. Are logical operations between integers (or even strings) implemented separately in lpython ?

def main0():
    a : i32
    b : i32
    x : i32 
    y : i32 
    or_op1 : i32
    or_op2 : i32
    a = 1
    b = 2
    x = 3
    y = 4
    or_op1 = a or b
    or_op2 = x or y
    print(or_op1,or_op2)

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

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
   Creating library try.lib and object try.exp
3 7

I'll do a quick similar check for logical and,not etc. and report if they give different results too !

Activity

  1. faze-geek commented on Feb 1, 2023

    @faze-geek
    ContributorAuthor

    and fails similarly and gives incorrect outputs in almost all attempts.

    def main0():
        a : i32
        b : i32
        x : i32 
        y : i32 
        and_op1 : i32
        and_op2 : i32
        a = 100
        b = 150
        x = 175
        y = 200
        and_op1 = a and b 
        and_op2 = x and y
        print(and_op1,and_op2)
    
    (lp) C:\Users\kunni\lpython>python try.py
    150 200
    
    (lp) C:\Users\kunni\lpython>src\bin\lpython try.py
       Creating library try.lib and object try.exp
    4 136
    
  2. changed the title [-]'or' operation of two integers gives wrong answers.[/-] [+]Logical operation of two integers gives wrong answers.[/+] on Feb 1, 2023
  3. certik commented on Feb 1, 2023

    @certik
    Contributor

    I think that's a bug. If it runs with LPython without any compile time or runtime errors or warnings, then it must behave exactly the same in CPython, and it clearly doesn't, based on your report. So we have to fix it, either not allow it in LPython, or fix it to produce the same answer.

  4. self-assigned this
    on Feb 1, 2023
  5. Smit-create commented on Feb 5, 2023

    @Smit-create
    Collaborator

    This fails for me with some other issue using main branch:

    from ltypes import i32
    
    def main0():
        a : i32
        b : i32
        x : i32
        y : i32
        or_op1 : i32
        or_op2 : i32
        a = 1
        b = 2
        x = 3
        y = 4
        or_op1 = a or b
        or_op2 = x or y
        print(or_op1,or_op2)
    
    main0()

    Error:

      File "/Users/thebigbool/repos/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 4349
        this->visit_expr(*x);
      File "../libasr/asr.h", line 4450
      File "../libasr/asr.h", line 4230
      File "/Users/thebigbool/repos/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 4654
        LCOMPILERS_ASSERT(ASRUtils::is_logical(*x.m_type))
    AssertFailed: ASRUtils::is_logical(*x.m_type)

    I'll try to fix this.

  6. anutosh491 commented on Feb 6, 2023

    @anutosh491
    Collaborator

    This fails for me with some other issue using main branch:

    I can confirm this ! I get the similar error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions