Skip to content

Arithmetic logic support #49292

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
szeredaiakos opened this issue May 28, 2022 · 5 comments
Closed

Arithmetic logic support #49292

szeredaiakos opened this issue May 28, 2022 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@szeredaiakos
Copy link

szeredaiakos commented May 28, 2022

Suggestion

Should be self-explanatory. But:

In short:
aNumber += (a<b) * 12 - (a>=b) * 14
Is significantly faster than:
if (a<b) { aNumber += 12} else {aNumber -= 14}

The first method ends up in error yet most major languages and runtimes handle it correctly.

🔍 Search Terms

arithmetic logic
ALU
arithmetic logic unit
performance

@MartinJohns
Copy link
Contributor

MartinJohns commented May 28, 2022

This is not self-explanatory at all, we're not mind readers. And TypeScript officially has no spec, so there's nothing to update.

A wild guess is be that you want #26382.

@szeredaiakos
Copy link
Author

This is not self-explanatory at all, we're not mind readers. And TypeScript officially has no spec, so there's nothing to update.

A wild guess is be that you want #26382.

It is unrelated.
Apparently is not so explanatory. Updating...

@MartinJohns
Copy link
Contributor

MartinJohns commented May 30, 2022

Unfortunately you still didn't fill out the issue template after updating. :-(

From that brief example it now looks like a duplicate of #27501. This is intentionally not supported: #27501 (comment)

It works fine if you add an explicit type conversion using Number(), which also makes your intent much clearer in the code.

@szeredaiakos
Copy link
Author

Unfortunately you still didn't fill out the issue template after updating. :-(

From that brief example it now looks like a duplicate of #27501. This is intentionally not supported: #27501 (comment)

It works fine if you add an explicit type conversion using Number(), which also makes your intent much clearer in the code.

Yes, casting is competitive, not quite the same tho. We may not argue about the clarity of code which uses logic arithmetic :).
Yes, thx, Martin!
Yes, this is a copy of #27501

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 31, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants