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

DM-9765: Suspicious numerical precision code in Angle #237

Merged
merged 3 commits into from May 25, 2017
Merged

Conversation

r-owen
Copy link
Contributor

@r-owen r-owen commented May 24, 2017

No description provided.

Copy link
Member

@kfindeisen kfindeisen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

if (wrapped - refAngRad < -PI) {
wrapped -= wrapped * 2.0 * std::numeric_limits<double>::epsilon();
wrapped += TWOPI;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is certainly cleaner, I do wonder why the original code didn't use TWOPI here when it did everywhere else.

Copy link
Contributor Author

@r-owen r-owen May 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the original code tried to keep within bounds at both ends in radians. By adding 2 pi the result may put wrapped - refAngRad >= 2 pi. Still, I'm inclined to live with that. The limits are squishy for other units anyway and we have no use case for precise limits. I will update the docs for wrapNear. Also the test needs some work to exercise cases where the upper limit is violated.

A test for the result of Angle.wrapNear being too small
applied the incorrect correction when the wrapped result was positive.
Added a test that shows the problem (it was not easy to trigger,
but setting wrapRef to 5 did the trick).
Adding wrapRef caused indentation to be so deep that I switched
to using itertools.product to tame it.
instead of adding a small value if the lower limit is exceeded,
add 2 pi. This simplies the code and gives better accuracy.
Use more specific asserts where useful.
Remove unneeded checks of angle != None.
Remove useless print statements.
@r-owen r-owen merged commit da074f1 into master May 25, 2017
@ktlim ktlim deleted the tickets/DM-9765 branch August 25, 2018 06:44
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.

None yet

2 participants