can building a C++ binary with -O3 change the results of my float operations? please…
- User
can building a C++ binary with -O3 change the results of my float operations? please cite sources
Assistant
Yes, compiling with -O3 can change the results of floating-point operations in C++. This happens because aggressive optimization can alter the order of operations or use different CPU instructions that may produce slightly different results due to floating-point arithmetic properties.
The C++ standard allows this behavior. According to the C++17 standard (ISO/IEC 14882:2017), section 8.3 about floating-point evaluation: "The values of operations with floating operands [...] are evaluated to a format whose range and precision may be greater than those of the type."
In practice, this means optimizers can:
- Use extended precision registers temporarily
- Reorder operations (changing associativity)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.