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

isfinite(x) misreports float values <= 0 as not finite. #343

Closed
d-leinhaeuser opened this issue May 19, 2015 · 1 comment
Closed

isfinite(x) misreports float values <= 0 as not finite. #343

d-leinhaeuser opened this issue May 19, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@d-leinhaeuser
Copy link

glm::isfinite from compatibility.inl returns false for float or double values that are less than or equal to 0.

The bug is in line 49:

return x >= std::numeric_limits<genType>::min() && x <= std::numeric_limits<genType>::max();

For floating point types with denormalization (see std::numeric_limits::has_denorm) std::numeric_limits::min() returns the smallest finite number greater than 0 that the type can represent instead of the smallest finite number overall.

The following should give the correct result for integer and floating point types:

if (std::numeric_limits<genType>::is_integer || std::denorm_absent == std::numeric_limits<genType>::has_denorm)
{
    return std::numeric_limits<genType>::min() <= x && std::numeric_limits<genType>::max() >= x;
}
else
{
    return -std::numeric_limits<genType>::max() <= x && std::numeric_limits<genType>::max() >= x;
}
@Groovounet Groovounet added the bug label Jul 19, 2015
@Groovounet Groovounet added this to the GLM 0.9.7 milestone Jul 19, 2015
@Groovounet Groovounet self-assigned this Jul 19, 2015
@Groovounet
Copy link
Member

This issue is fixed in master branch for GLM 0.9.7 release

Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants