Improve complex binop and add .real, .imag attributes#232
Closed
Smit-create wants to merge 5 commits intolcompilers:mainfrom
Closed
Improve complex binop and add .real, .imag attributes#232Smit-create wants to merge 5 commits intolcompilers:mainfrom
.real, .imag attributes#232Smit-create wants to merge 5 commits intolcompilers:mainfrom
Conversation
Smit-create
commented
Mar 15, 2022
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( |
Collaborator
Author
There was a problem hiding this comment.
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); |
Collaborator
Author
There was a problem hiding this comment.
Presently this fails on the following check:
def test():
x: c64
x = 2 + 3j
a: f64
a = x.imagASR:
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; |
Collaborator
Author
There was a problem hiding this comment.
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; |
Contributor
|
Let's separate the two changes here into two PRs. I think you already have one PR for the implicit casting change. |
This was referenced Mar 18, 2022
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #229