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

Remove the need to calculate sqrt by using squared distance #342

Merged
merged 3 commits into from
Nov 27, 2021

Conversation

GilesBathgate
Copy link
Contributor

Description

Minor performance tweak. When doing distance comparisons (c^2 = a^2+b^2), you can calculate c < 10, or you can do c^2 < 100.

Behaviour/ Breaking changes

Expect the same behaviour, and probably no noticeable performance gain, but still...

Have you tested the changes?

Yes, seems to work with MK3 as before.

@GilesBathgate
Copy link
Contributor Author

Also note (f/5)^2 = f^2/5^2 ;)

@vintagepc
Copy link
Owner

Unfortunately the OSX compiler doesn't recognize that syntax:

/Users/runner/work/MK404/MK404/parts/components/PINDA.cpp:47:25: error: result of '10^2' is 8; did you mean '1e2'? [-Werror,-Wxor-used-as-pow]
                        if (fEdistSquared<(10^2))
                                           ~~^~
                                           1e2
/Users/runner/work/MK404/MK404/parts/components/PINDA.cpp:47:25: note: replace expression with '0xA ^ 2' or use 'xor' instead of '^' to silence this warning

@vintagepc
Copy link
Owner

vintagepc commented Nov 27, 2021

... and more importantly, ^ is bitwise XOR, not "power"

@GilesBathgate
Copy link
Contributor Author

@vintagepc Oh dear, schoolboy error. I've fixed it.

@codecov
Copy link

codecov bot commented Nov 27, 2021

Codecov Report

Merging #342 (5a9e9c3) into master (c1a0c6b) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #342   +/-   ##
=======================================
  Coverage   91.14%   91.14%           
=======================================
  Files         166      166           
  Lines        7692     7692           
=======================================
  Hits         7011     7011           
  Misses        681      681           
Impacted Files Coverage Δ
parts/components/PINDA.cpp 96.87% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1a0c6b...5a9e9c3. Read the comment docs.

@vintagepc vintagepc merged commit 80168bd into vintagepc:master Nov 27, 2021
@GilesBathgate GilesBathgate deleted the remove-sqrt-pinda branch November 27, 2021 19:43
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.

2 participants