-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
constexpr as much of half as possible (#87)
This is the remaining section of `half` that can be easily constexpr. The way they are currently implemented, the basic half-from-float ctr and half-to-float cast are not able to be constexpr, and that in turn prevents almost all the arithmetic operations (which convert to float, do the math, then convert back) from being constexpr. This is the closest we're going to get with the current implementations. The most offensive parts to constexpr are the use of table lookups, and the strange overflow() trying to raise a hardware overflow exception. It's not hard to imagine alternate implementations that don't work the same way at all, but we must leave that for another day (and maybe for somebody who is more willing to chase down ever corner case of IEEE754 logic). I added private mantissa() and exponent() helper methods, using those helped me make some other public methods be constexpr in C++11 by making their body be a single return statement (if you spread over multiple statements, you become constexpr in C++14 only on some compilers). We could make those public if people think there are other uses for these helpers. Signed-off-by: Larry Gritz <[email protected]>
- Loading branch information
Showing
1 changed file
with
53 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters