+ runtime check of rounding mode support#8
Conversation
|
Ok, I'm confused. I tried your program using gcc 5.1 on Mac OS X, and it did nothing with both What is the behavior that you expect from this program (and what is the behavior that you observe)? |
|
I expect (and I observe with gcc 5.1.0, clang 3.6.0 on ArchLinux) that after applying my patch for Boost.Interval program built without -frounding-math aborted with error Possibly, absence of crash on MAC OS X can be explained by another set of predefined command line options for gcc. Could you try to pass |
|
👍 |
|
Couldn't this be a compile-time check? |
|
I'm afraid no. Firstly constexpr evaluation doesn't support rounding mode. Secondly correctly built program will crash if run it on Valgrind. |
|
Using the docker ubuntu bionic image (clang 6, gcc 7.3, valgrind 3.13, found in boostorg/boost#184) I am able to reproduce this issue on the "pi" test in release mode: gcc with -fno-rounding-math: gcc with -frounding-math: clang 6: Unable to use clang with -fno-rounding-math: As it stands you can't use clang at all, and you can only use gcc in one mode. I'm thinking it's the library or the test that's at fault here and not the compiler(s)... |
| template<> | ||
| struct rounded_math<double> | ||
| : save_state<rounded_arith_opp<double> > | ||
| , private detail::runtime_checker<double> |
There was a problem hiding this comment.
Won't this increase the runtime performance significantly if these are used in hot code paths?
There was a problem hiding this comment.
It shouldn't because it is invoking only once (static helper _, line 59). There is still some performance penalty due to the check that singleton of the type helper is initialized, but I believe that it's insignificant in comparison to the cost of switch of rounding mode.
jeking3
left a comment
There was a problem hiding this comment.
Please rebase on develop.
For example, following program
<code>
#include <boost/numeric/interval.hpp>
int main()
{
boost::numeric::interval<double>::traits_type::rounding _;
}
</code>
will work fine if is built with gcc using '-frounding-math', but will fail otherwise.
Running on Valgrind is another practical case when this program will crash (even if it was correctly built).
For example, following program
will work fine if is built with gcc using '-frounding-math', but will fail otherwise.
Running on Valgrind is another practical case when this program will crash (even if it was correctly built).
I am not sure about using
assertfor check, may be exception or some other mechanism should be used.