I write a cross-platform program for Windows and Linux, and I would like it to behave as similar on both platforms as possible. I use some mathematics in the program, e.g. std::atan2 function calls, and I observed that for the same input values it produces sometimes the result diverging in the unit of least precision depending on the platform or optimization settings.

Consider this reduced example:

#include <print> #include <cmath> int main() { // 0.14189707 with GCC on Linux // 0.14189705 with MSVC (and compile-time evaluation in GCC) std::print( "{}", std::atan2( 1.f, 7.f ) ); }

Online demo. Although the difference between results is small, it is amplified by the following computations in my program, so I would like to avoid the difference completely.

Are implementations allowed diverging in that way provided the same rounding mode? Are there compiler flags to eliminate or minimize the divergence?

Fedor's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.