Namespaces
Variants
Views
Actions

Talk:cpp/numeric/math/rint

From cppreference.com

I struggle understanding the documentation as the example provides inconsistent results:


rounding down (gcc 4.9 && gcc 5.2):

 rint(+3.5) = 3

rounding down (gcc 11.1 && clang 5.0):

 rint(+3.5) = 4

the preprocessor directive is unknown on all compilers:

 #pragma STDC FENV_ACCESS ON

This is same for the example of the C version. 82.83.94.139 02:43, 2 June 2022 (PDT)

It seems as mentioned compilers so not execute subsequent calls to std::fesetround in order. 82.83.94.139 03:13, 2 June 2022 (PDT)
So meanwhile I understand how this is caused by the unknown pragma. Still it is bad to have broken examples and no hint (not even on std::fesetround, or FE_round, just some optimistic remark on the overview). 82.83.94.139 07:08, 2 June 2022 (PDT)
Both compilers execute the fesetround calls in order, but with optimization on, they cache the first rint call and just reuse its result the second time it appears in the source code even though fenv had changed. With clang, I can fix it by using -frounding-math (which disables rounding mode sensitive optimizations), but with gcc it seems to have no effect - might be a compiler bug there. Indeed worth a note. --Cubbi (talk) 08:38, 2 June 2022 (PDT)
oh, with GCC, it's a known bug 34678 --Cubbi (talk) 19:55, 12 June 2022 (PDT)