Skip to content

Commit 48d2382

Browse files
tagunilJordanYates
authored andcommitted
tests: math: interpolation: disable floating point contraction
This test cannot tolerate any loss of precision, including the one caused by the compiler contracting floating points operations together, like in fused multiply-add (FMA). Some toolchains enable FP contraction by default, so disable it for the specific test and let the user decide themselves whether precision or performance is needed for their specific application. Co-authored-by: Jordan Yates <[email protected]> Co-authored-by: Ilya Tagunov <[email protected]> Signed-off-by: Ilya Tagunov <[email protected]>
1 parent 5011eba commit 48d2382

File tree

1 file changed

+12
-0
lines changed
  • tests/lib/math/interpolation/src

1 file changed

+12
-0
lines changed

tests/lib/math/interpolation/src/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
#include <math.h>
77

88
#include <zephyr/ztest.h>
9+
10+
#ifdef __clang__
11+
/*
12+
* Floating-point contraction merges an operation of the form (a*b + c) from
13+
* two operations (fmul, fadd) into a single operation (fmadd). This can change
14+
* the value of the resulting LSB, causing problems when the expected value is
15+
* some multiple of 0.5f and the rounding functions are used. Disable
16+
* contraction for the tests to ensure this doesn't occur.
17+
*/
18+
#pragma STDC FP_CONTRACT OFF
19+
#endif
20+
921
#include <zephyr/math/interpolation.h>
1022

1123
ZTEST(interpolation, test_interpolation_oob)

0 commit comments

Comments
 (0)