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

fix: don't use floats in for loops #5651

Merged
merged 2 commits into from
Jan 5, 2025

Conversation

firefly2442
Copy link
Contributor

Do not use floating-point variables as loop counters
Using floating-point variables should not be used as loop counters, as they are not precise, which may result in incorrect loops. A loop counter is a variable that is changed with each iteration and controls when the loop should terminate. It is decreased or increased by a fixed amount each iteration.
See rule NUM09-J.

Bug kind and pattern: FL - FL_FLOATS_AS_LOOP_COUNTERS

Found via SpotBugs

Also has a few other cleanups like consistency with doubles (don't use f) and an unneeded conditional check for modulus.

Do not use floating-point variables as loop counters
Using floating-point variables should not be used as loop counters, as they are not precise, which may result in incorrect loops. A loop counter is a variable that is changed with each iteration and controls when the loop should terminate. It is decreased or increased by a fixed amount each iteration.
See rule NUM09-J.

Bug kind and pattern: FL - FL_FLOATS_AS_LOOP_COUNTERS
Do not use floating-point variables as loop counters
Using floating-point variables should not be used as loop counters, as they are not precise, which may result in incorrect loops. A loop counter is a variable that is changed with each iteration and controls when the loop should terminate. It is decreased or increased by a fixed amount each iteration.
See rule NUM09-J.

Bug kind and pattern: FL - FL_FLOATS_AS_LOOP_COUNTERS
@codecov-commenter
Copy link

codecov-commenter commented Jan 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 10.03%. Comparing base (8dbf74b) to head (db3a8a1).
Report is 22 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #5651   +/-   ##
=========================================
  Coverage     10.02%   10.03%           
- Complexity     6069     6075    +6     
=========================================
  Files          1074     1074           
  Lines        141609   141600    -9     
  Branches      20646    20645    -1     
=========================================
+ Hits          14203    14216   +13     
+ Misses       126032   126013   -19     
+ Partials       1374     1371    -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HammerGS HammerGS merged commit d0609a9 into MegaMek:master Jan 5, 2025
4 checks passed
@firefly2442 firefly2442 deleted the floats-in-loops branch January 5, 2025 19:45
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 this pull request may close these issues.

3 participants