Set errc::result_out_of_range on over/underflow#189
Set errc::result_out_of_range on over/underflow#189lemire merged 2 commits intofastfloat:mainfrom alugowski:out_of_range
Conversation
|
@alugowski Please review the failing tests. |
Best-effort values are still returned, such as 0 for underflow and infinity for overflow, but now the returned ec is set to std::errc::result_out_of_range instead of std::errc().
|
@lemire should be fixed. Curious why these didn't fail when I was working on that same file last night :) |
Gremlins. |
|
@lemire do you have thoughts on this GCC 9, fast-math run failure? The Values that are expected to underflow are parsed successfully, namely values in the range [1e-323, 1e-308]. That sounds like the subnormal range. I'm unclear what the desired behavior is in this case. |
|
Adding the denormals to the Is this an acceptable fix? I'm hesitant only because I'm surprised to be the first to hit this. |
Please try it. It is not like your table can be less accurate than a runtime computation.
I am not sure. One would need to examine the assembly, but the most likely explanation, reading your code, is that the compiler goes out and does some lossy approximation (triggered by your new code). It does not imply that your code is itself a problem. We may simply have been lucky so far. I might have missed something, but your code looks clean and correct. |
On some platforms std::pow returns 0 instead of a subnormal number with `-ffast-math -O2` compiler options.
|
Updated PR. Works on my system. If I had to guess I'm going with bool is_pow_correct{1e-308 == std::pow(10,-308)};then the test skips subnormals and wouldn't alert on any differences. |
|
I will issue a release. |
Appreciate it! Given that that test still fails, I looked more into it and it looks like the subnormal range is platform specific, and even method-specific within a platform. This GCC bug shows that I tried that code with Apple Clang 14 and GCC 12 and got different results. Only GCC's istringstream parsed If neither explicit constants nor |
|
I found another solution that makes GCC 9 happy. PR: #190 |
In fastfloat#189 the behavior on underflow was changed to better match the standard's recommendations, but the README does not mention underflow explicitly.
Best-effort values are still returned, such as 0 for underflow and infinity for overflow, but now the returned
ecis set tostd::errc::result_out_of_rangeinstead ofstd::errc().See #120