Skip to content

Commit

Permalink
tests: math: interpolation: disable floating point contraction
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tagunil and JordanYates committed Jan 8, 2025
1 parent 52fd016 commit e9e058b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/lib/math/interpolation/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
#include <math.h>

#include <zephyr/ztest.h>

#ifdef __clang__
/*
* Floating-point contraction merges an operation of the form (a*b + c) from
* two operations (fmul, fadd) into a single operation (fmadd). This can change
* the value of the resulting LSB, causing problems when the expected value is
* some multiple of 0.5f and the rounding functions are used. Disable
* contraction for the tests to ensure this doesn't occur.
*/
#pragma STDC FP_CONTRACT OFF
#endif

#include <zephyr/math/interpolation.h>

ZTEST(interpolation, test_interpolation_oob)
Expand Down

0 comments on commit e9e058b

Please sign in to comment.