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

Compare alternative IF performance to implemented one #614

Open
ohhmm opened this issue Dec 8, 2024 · 0 comments
Open

Compare alternative IF performance to implemented one #614

ohhmm opened this issue Dec 8, 2024 · 0 comments

Comments

@ohhmm
Copy link
Owner

ohhmm commented Dec 8, 2024

An alternative approach:

lets describe mathematically this expression: "if m=0 then a=1" [ else a=a ]

Using mathematical notation, we can write this expression as:

if(m,a) = abs(sign(m))*a + (1 + sign(m))/2 * a
if(m,a) = ((1 - m/|m|)/2 + (1 + m/|m|)/2) * a

This expression uses the sign function, which returns -1 if m is negative, 0 if m is zero, and 1 if m is positive. If m is zero, the first term evaluates to 1/2 and the second term evaluates to a,
so the expression simplifies to a = 1/2 + 1/2 * a, which yields a = 1.
If m is not zero, the first term evaluates to 0 and the second term evaluates to a, so the expression simplifies to a = a, which is true for any value of a.

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

No branches or pull requests

1 participant