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

Checking that a local expression is zero #585

Open
vsht opened this issue Nov 20, 2024 · 5 comments · May be fixed by #588
Open

Checking that a local expression is zero #585

vsht opened this issue Nov 20, 2024 · 5 comments · May be fixed by #588
Milestone

Comments

@vsht
Copy link

vsht commented Nov 20, 2024

Dear all,

I know that it's a stupid question, but I really wasn't able to find an elegant way solve it without complicating
everything too much. So is there a simple way to check if the given local expression is zero during the execution?

Consider for example

S a,b; 
L exp1 = a+b;
L exp2 = a*b;
.sort
id a=-b;
.sort
* More code
print;
.end

here exp1 becomes zero after the id statement, while exp2 is not zero. Ideally, I would like to detect exp1 vanishing and finish the program right here (or maybe jump to the end), instead of going through all the subsequent code instructions.

Cheers,
Vlad

@jodavies
Copy link
Collaborator

Yes, I think it is undocumented but you can do, e.g.,

S a,b;
L exp1 = a+b;
L exp2 = a*b;
.sort
id a=-b;
.sort
#do e = {`activeexprnames_'}
   #if `ZERO_`e''
      #message `e' is zero
   #endif
#enddo
.end

@vsht
Copy link
Author

vsht commented Nov 20, 2024

Many thanks!

@jodavies jodavies reopened this Nov 20, 2024
@jodavies jodavies added this to the v4.3.2 milestone Nov 20, 2024
@jodavies
Copy link
Collaborator

We should an explanation of this (and UNCHANGED_) to the manual.

@StHagel
Copy link

StHagel commented Nov 22, 2024

Yes, I think it is undocumented but you can do, e.g.,

S a,b;
L exp1 = a+b;
L exp2 = a*b;
.sort
id a=-b;
.sort
#do e = {`activeexprnames_'}
   #if `ZERO_`e''
      #message `e' is zero
   #endif
#enddo
.end

This loops over all local expressions though, right? Is there a way to check just one specific expression?

@jodavies
Copy link
Collaborator

Sure, you use ZERO_exprname for whichever exprname you want.

@jodavies jodavies linked a pull request Nov 25, 2024 that will close this issue
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 a pull request may close this issue.

3 participants