Skip to content

Commit

Permalink
tests: lib: c_lib: fix double promotion error
Browse files Browse the repository at this point in the history
Fix double promotion warnings

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
  • Loading branch information
XenuIsWatching committed Dec 13, 2023
1 parent bb1617c commit a5c9c39
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tests/lib/c_lib/common/src/test_sqrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#define local_abs(x) (((x) < 0) ? -(x) : (x))

#ifndef NAN
#define NAN (__builtin_nansf(""))
#define NAN (__builtin_nans(""))
#endif

#ifndef NANF
#define NANF (__builtin_nans(""))
#define NANF (__builtin_nansf(""))
#endif

#ifndef INF
Expand Down Expand Up @@ -91,14 +91,13 @@ static int isnanf(float x)
#endif

/* small errors are expected, computed as percentage error */
#define MAX_FLOAT_ERROR_PERCENT (3.5e-5)
#define MAX_FLOAT_ERROR_PERCENT (3.5e-5f)
#define MAX_DOUBLE_ERROR_PERCENT (4.5e-14)

ZTEST(libc_common, test_sqrtf)
{
int i;
float exponent, resf, square, root_squared;
double error;
float exponent, resf, square, root_squared, error;
uint32_t max_error;
int32_t ierror;
int32_t *p_square = (int32_t *)&square;
Expand Down Expand Up @@ -129,7 +128,7 @@ int32_t *p_root_squared = (int32_t *)&root_squared;
if ((resf > 0.0f) && (resf < INFF)) {
error = (square - root_squared) /
square * 100;
if (error < 0.0) {
if (error < 0.0f) {
error = -error;
}
/* square and root_squared should be almost identical
Expand All @@ -143,7 +142,7 @@ int32_t *p_root_squared = (int32_t *)&root_squared;
}
} else {
/* negative, +NaN, -NaN, inf or -inf */
error = 0.0;
error = 0.0f;
}
zassert_true(error < MAX_FLOAT_ERROR_PERCENT,
"max sqrtf error exceeded");
Expand Down

0 comments on commit a5c9c39

Please sign in to comment.