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: avoid overflow on overflow check in toms748_solve safe_div #941

Closed

Conversation

mckib2
Copy link
Contributor

@mckib2 mckib2 commented Feb 4, 2023

@@ -160,7 +160,8 @@ inline T safe_div(T num, T denom, T r)

if(fabs(denom) < 1)
{
if(fabs(denom * tools::max_value<T>()) <= fabs(num))
constexpr T inv_max_value = 1.0 / tools::max_value<T>();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
constexpr T inv_max_value = 1.0 / tools::max_value<T>();
const T inv_max_value = 1.0 / tools::max_value<T>();

As @jzmaddock noted in #942 we still need to support types that don't have constexpr construction.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Even better make that static const and then it's evaluated just the once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented

@mckib2 mckib2 force-pushed the toms748-solve-mac-m1-overflow-fix branch from 3cf46ad to 9b0a6be Compare February 5, 2023 05:16
@mckib2
Copy link
Contributor Author

mckib2 commented Feb 5, 2023

Superceded by #945

@mckib2 mckib2 closed this Feb 5, 2023
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