Compiler floating-point operation optimizations causing non-BE behaviour
Starting from version 14 Apple clang compiler changed the default behaviour of FP contraction (FMA) from off
to on
. This attempts to optimize certain floating point operations, but may cause inaccurate results, e.g., on ARM Macs (short description).
This problem was observed when working on !1160 (merged) as it caused non-BE behaviour in the output before and after refactoring.
Two potential fixes:
- Disable the optimizations with
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffp-contract=off")
- Or, build the project for x86 instead of native architecture
-D CMAKE_OSX_ARCHITECTURES=x86_64