Skip to content

Commit d64ea4e

Browse files
committed
Make small changes to libm-test.c to improve portability.
- Don't define llabs(). This breaks if llabs() is already a macro, which is allowed by the C standard/POSIX. llabs() was introduced in C99, so I think we can safely assume it is present on all interesting systems. - Cast the parameters to fabs() to the floating point type. Clang has introduced some interesting warnings that trigger if the arguments to fabs*() are not the right type.
1 parent b6ff8bb commit d64ea4e

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

test/libm-test.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,6 @@ check_longlong (const char *test_name, long long int computed,
712712

713713
test_exceptions (test_name, exceptions);
714714
noTests++;
715-
#define llabs(x) (x < 0 ? -x : x)
716715
if (llabs (diff) <= max_ulp)
717716
ok = 1;
718717

@@ -2531,15 +2530,15 @@ fabs_test (void)
25312530
{
25322531
init_max_error ();
25332532

2534-
check_float ("fabs (0) == 0", FUNC(fabs) (0), 0, 0, 0, 0);
2533+
check_float ("fabs (0) == 0", FUNC(fabs) ((FLOAT)0.0), 0, 0, 0, 0);
25352534
check_float ("fabs (-0) == 0", FUNC(fabs) (minus_zero), 0, 0, 0, 0);
25362535

25372536
check_float ("fabs (inf) == inf", FUNC(fabs) (plus_infty), plus_infty, 0, 0, 0);
25382537
check_float ("fabs (-inf) == inf", FUNC(fabs) (minus_infty), plus_infty, 0, 0, 0);
25392538
check_float ("fabs (NaN) == NaN", FUNC(fabs) (nan_value), nan_value, 0, 0, 0);
25402539

2541-
check_float ("fabs (38.0) == 38.0", FUNC(fabs) (38.0), 38.0, 0, 0, 0);
2542-
check_float ("fabs (-e) == e", FUNC(fabs) (-M_El), M_El, 0, 0, 0);
2540+
check_float ("fabs (38.0) == 38.0", FUNC(fabs) ((FLOAT)38.0), 38.0, 0, 0, 0);
2541+
check_float ("fabs (-e) == e", FUNC(fabs) ((FLOAT)-M_El), M_El, 0, 0, 0);
25432542

25442543
print_max_error ("fabs", 0, 0);
25452544
}

0 commit comments

Comments
 (0)