Skip to content

Improve complex binop and add .real, .imag attributes #232

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

Closed
wants to merge 5 commits into from

Conversation

Smit-create
Copy link
Collaborator

Fixes #229

@Smit-create Smit-create marked this pull request as draft March 14, 2022 14:28
Comment on lines +1039 to +1041
} else if (ASRUtils::is_complex(*left_type) && !ASRUtils::is_complex(*right_type)) {
if (ASRUtils::is_real(*right_type)) {
return ASR::down_cast<ASR::expr_t>(ASR::make_ImplicitCast_t(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will change this to

Suggested change
} else if (ASRUtils::is_complex(*left_type) && !ASRUtils::is_complex(*right_type)) {
if (ASRUtils::is_real(*right_type)) {
return ASR::down_cast<ASR::expr_t>(ASR::make_ImplicitCast_t(
} else if (!is_assign && ASRUtils::is_complex(*left_type) && !ASRUtils::is_complex(*right_type)) {
if (ASRUtils::is_real(*right_type)) {
return ASR::down_cast<ASR::expr_t>(ASR::make_ImplicitCast_t(

}
if (ASR::is_a<ASR::Variable_t>(*t)) {
ASR::Variable_t *var = ASR::down_cast<ASR::Variable_t>(t);
LFORTRAN_ASSERT(var->m_value);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Presently this fails on the following check:

def test():
    x: c64
    x = 2 + 3j
    a: f64
    a = x.imag

ASR:

AssertFailed: var->m_value

This might be because we are keeping value as nullptr while creating a variable which I expect to be changed after the assignment. @certik What are your views/suggestions on this?

8, nullptr, 0));
tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, val, type);
} else if (attr == "real") {
double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value)->m_im;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix this:

Suggested change
double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value)->m_im;
double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value)->m_re;

@certik
Copy link
Contributor

certik commented Mar 15, 2022

Let's separate the two changes here into two PRs. I think you already have one PR for the implicit casting change.

@Smit-create
Copy link
Collaborator Author

Closing this for #256 and #252

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.

Implement .real and .imag attributes on complex numbers
2 participants