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

ska_sort should reject non-IEEE 754 floating points #2

Open
Morwenn opened this issue Jan 4, 2017 · 1 comment
Open

ska_sort should reject non-IEEE 754 floating points #2

Morwenn opened this issue Jan 4, 2017 · 1 comment

Comments

@Morwenn
Copy link

Morwenn commented Jan 4, 2017

If I'm not mistaken, the bit tricks used to reinterpret the floating point numbers as integers are specific to the IEEE 754 representation of floating point numbers, which isn't guaranteed by the C++ standard. Instead of blindly accepting every standard floating point type, you should guard the sort at compile-time with std::numeric_limits<T>::is_iec559 so that it rejects non-IEEE 754 compliant floating points types.

Additionally, you're using type punning through an union between integral and floating point type, which is undefined behaviour. A standard compliant solution would be to use std::memcpy instead.

@Morwenn
Copy link
Author

Morwenn commented Jan 10, 2017

I added a few compile-time checks to my ska-sorter branch in cpp-sort. You might want to have some of those checks as static_assert to avoid problems such as the ones described above for float and double on strange targets :)

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

1 participant