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

glm::equal(val1, val2, int ULPs) gives the wrong answer #965

Closed
petersteneteg opened this issue Oct 29, 2019 · 6 comments
Closed

glm::equal(val1, val2, int ULPs) gives the wrong answer #965

petersteneteg opened this issue Oct 29, 2019 · 6 comments
Assignees
Milestone

Comments

@petersteneteg
Copy link

This test

if(a.negative() != b.negative())
{
// Check for equality to make sure +0==-0
return a.mantissa() == b.mantissa() && a.exponent() == b.exponent();
}

will return true for any two number of different sign but with equal magnitude.

the test on line 30 should be return x==y;

Example
https://godbolt.org/z/iR8unh

@Groovounet Groovounet added this to the GLM 0.9.9 milestone Nov 2, 2019
@Groovounet Groovounet self-assigned this Nov 2, 2019
@Groovounet
Copy link
Member

This issue should be fixed in master branch.

Thanks for contributing,
Christophe

@petersteneteg
Copy link
Author

Should not -0.0f be equal to 0.0f?

@petersteneteg
Copy link
Author

Btw this code is also in vector_relational.inl

@petersteneteg
Copy link
Author

@Groovounet see above

@Groovounet
Copy link
Member

Do you have an idea how to implement this correctly?

@petersteneteg
Copy link
Author

This is definitely not in my expertise, but looking at the article referenced from
https://github.com/g-truc/glm/blob/master/glm/detail/type_float.hpp

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

I would guess something similar to this...

    // Different signs means they do not match.
    if (uA.Negative() != uB.Negative())
    {
        // Check for equality to make sure +0==-0
        if (A == B)
            return true;
        return false;
    }

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

No branches or pull requests

2 participants