Skip to content

Integers do not get casted in operations with complex variables #1524

Open
@faze-geek

Description

@faze-geek

While playing with the complex module I saw certain expressions giving incorrect results .In Python, when an integer is operated with objects of complex() class the integer is implicitly casted to a complex variable with 0 imaginary value.

y = complex(5)+100
print(y)
(lp) C:\Users\kunni\lpython>python try.py
(105+0j)

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
(5.000000,0.000000)
y = complex(5)*10
print(y)
(lp) C:\Users\kunni\lpython>python try.py
(50+0j)

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
(0.000000,0.000000)
y = c32(5)-10
print(y)
(lp) C:\Users\kunni\lpython>python try.py
(-5+0j)

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

Metadata

Metadata

Assignees

No one assigned

    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