Skip to content

[lint request] mul_add #4001

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
gnzlbg opened this issue Apr 18, 2019 · 3 comments
Closed

[lint request] mul_add #4001

gnzlbg opened this issue Apr 18, 2019 · 3 comments
Labels
A-lint Area: New lints L-perf Lint: Belongs in the perf lint group

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 18, 2019

Floating-point code of the form a * b + c can be better optimized when written as a.mul_add(b, c), but this might change its result because instead of first computing a * b, rounding that, and then adding c to it, and rounding that, a.mul_add(b, c) computes a * b + c with infinite precision, and only rounds the end result.

I think it makes sense to recommend people by default that, if they don't care about their result being computed with higher-precission (and their results changing), they should prefer to use a.mul_add(b, c) instead of a * b + c (otherwise they can ignore the lint).

@matthiaskrgr matthiaskrgr added L-perf Lint: Belongs in the perf lint group A-lint Area: New lints labels Apr 19, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Apr 24, 2019

I think it's fine for a perf lint to change corner case semantics slightly. If the change is truly undesired, the lint can be allowed and a comment placed as to why the change is not desirable at the given location.

@EthanTheMaster
Copy link
Contributor

I would like to make this lint. This seems like a cool first lint to make.

EthanTheMaster added a commit to EthanTheMaster/rust-clippy that referenced this issue Sep 28, 2019
bors added a commit that referenced this issue Oct 8, 2019
Add suggestion for mul_add

Issue #4001: Whenever `a*b+c` is found where `a`,`b`, and `c` are floats, a lint is suggested saying to use `a.mul_add(b, c)`. Using `mul_add` may give a performance boost depending on the target architecture and also has higher numerical accuracy as there is no round off when doing `a*b`.

changelog: New lint: `manual_mul_add`
EthanTheMaster added a commit to EthanTheMaster/rust-clippy that referenced this issue Oct 8, 2019
Fixed typo

Fixes lint name and uses appropriate linting suggestion

changed lint help message

Added autofixable test

Added Autofixable Test

Removed Broken Autofixable File

updated lints

Generated Autofixable/Nonfixable Test Cases

Changed Suggestion Applicability
EthanTheMaster added a commit to EthanTheMaster/rust-clippy that referenced this issue Oct 8, 2019
Fixed typo

Fixes lint name and uses appropriate linting suggestion

changed lint help message

Added autofixable test

Added Autofixable Test

Removed Broken Autofixable File

updated lints

Generated Autofixable/Nonfixable Test Cases

Changed Suggestion Applicability

Fixed Lint List Count
EthanTheMaster added a commit to EthanTheMaster/rust-clippy that referenced this issue Oct 8, 2019
Fixed typo

Fixes lint name and uses appropriate linting suggestion

changed lint help message

Added autofixable test

Added Autofixable Test

Removed Broken Autofixable File

updated lints

Generated Autofixable/Nonfixable Test Cases

Changed Suggestion Applicability

Updated Lint Count
bors added a commit that referenced this issue Oct 8, 2019
Add suggestion for mul_add

Issue #4001: Whenever `a*b+c` is found where `a`,`b`, and `c` are floats, a lint is suggested saying to use `a.mul_add(b, c)`. Using `mul_add` may give a performance boost depending on the target architecture and also has higher numerical accuracy as there is no round off when doing `a*b`.

changelog: New lint: `manual_mul_add`
@rye
Copy link

rye commented Oct 20, 2019

I think this was closed by #4602?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-perf Lint: Belongs in the perf lint group
Projects
None yet
Development

No branches or pull requests

6 participants