diff options
Diffstat (limited to 'math')
-rw-r--r-- | math/libm-test.c | 97 | ||||
-rw-r--r-- | math/math.h | 6 | ||||
-rw-r--r-- | math/test-fenv.c | 44 |
3 files changed, 121 insertions, 26 deletions
diff --git a/math/libm-test.c b/math/libm-test.c index 7093fdc..e51bfe3 100644 --- a/math/libm-test.c +++ b/math/libm-test.c @@ -46,6 +46,7 @@ fabs, fdim, floor, fma, fmax, fmin, fmod, fpclassify, frexp, gamma, hypot, ilogb, isfinite, isinf, isnan, isnormal, + isless, islessequal, isgreater, isgreaterequal, islessgreater, isunordered, ldexp, lgamma, log, log10, log1p, log2, logb, modf, nearbyint, nextafter, pow, remainder, remquo, rint, lrint, llrint, @@ -60,7 +61,7 @@ conj, cproj, cimag, creal, drem, j0, j1, jn, y0, y1, yn, significand, - nan, comparison macros (isless,isgreater,...). + nan The routines using random variables are still under construction. I don't like it the way it's working now and will change it. @@ -361,7 +362,7 @@ check_equal (MATHTYPE computed, MATHTYPE supplied, MATHTYPE eps, MATHTYPE * diff ret_value = (*diff <= eps && (signbit (computed) == signbit (supplied) || eps != 0.0)); - /* Make sure the subtraction/comparsion have no influence on the exceptions. */ + /* Make sure the subtraction/comparison have no influence on the exceptions. */ feclearexcept (FE_ALL_EXCEPT); return ret_value; @@ -2458,6 +2459,7 @@ sqrt_test (void) x = random_value (0, 10000); check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x); check ("sqrt (4) == 2", FUNC(sqrt) (4), 2); + check ("sqrt (2) == 1.14142...", FUNC(sqrt) (2), M_SQRT2l); check ("sqrt (0.25) == 0.5", FUNC(sqrt) (0.25), 0.5); check ("sqrt (6642.25) == 81.5", FUNC(sqrt) (6642.25), 81.5); check_eps ("sqrt (15239.903) == 123.45", FUNC(sqrt) (15239.903), 123.45, @@ -5530,6 +5532,95 @@ fma_test (void) } +/* + Tests for the comparison macros + */ +typedef enum {is_less, is_equal, is_greater, is_unordered} comp_result; + + +static void +comparison2_test (MATHTYPE x, MATHTYPE y, comp_result comp) +{ + char buf[255]; + int result; + int expected; + + expected = (comp == is_greater); + sprintf (buf, "isgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y, + expected); + result = (isgreater (x, y) == expected); + check_bool (buf, result); + + expected = (comp == is_greater || comp == is_equal); + sprintf (buf, "isgreaterequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y, + expected); + result = (isgreaterequal (x, y) == expected); + check_bool (buf, result); + + expected = (comp == is_less); + sprintf (buf, "isless (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y, + expected); + result = (isless (x, y) == expected); + check_bool (buf, result); + + expected = (comp == is_less || comp == is_equal); + sprintf (buf, "islessequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y, + expected); + result = (islessequal (x, y) == expected); + check_bool (buf, result); + + expected = (comp == is_greater || comp == is_less); + sprintf (buf, "islessgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y, + expected); + result = (islessgreater (x, y) == expected); + check_bool (buf, result); + + expected = (comp == is_unordered); + sprintf (buf, "isunordered (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y, + expected); + result = (isunordered (x, y) == expected); + check_bool (buf, result); + +} + + +static void +comparison1_test (MATHTYPE x, MATHTYPE y, comp_result comp) +{ + comp_result comp_swap; + switch (comp) + { + case is_less: + comp_swap = is_greater; + break; + case is_greater: + comp_swap = is_less; + break; + default: + comp_swap = comp; + break; + } + comparison2_test (x, y, comp); + comparison2_test (y, x, comp_swap); +} + + +static void +comparisons_test (void) +{ + comparison1_test (1, 2, is_less); + comparison1_test (-30, 30, is_less); + comparison1_test (42, 42, is_equal); + comparison1_test (1, plus_infty, is_less); + comparison1_test (35, minus_infty, is_greater); + comparison1_test (1, nan_value, is_unordered); + comparison1_test (nan_value, nan_value, is_unordered); + comparison1_test (plus_infty, nan_value, is_unordered); + comparison1_test (minus_infty, nan_value, is_unordered); + comparison1_test (plus_infty, minus_infty, is_greater); +} + + static void inverse_func_pair_test (const char *test_name, mathfunc f1, mathfunc inverse, @@ -5838,6 +5929,8 @@ main (int argc, char *argv[]) isnormal_test (); signbit_test (); + comparisons_test (); + /* trigonometric functions */ acos_test (); asin_test (); diff --git a/math/math.h b/math/math.h index 5103f2e..6c2ef27 100644 --- a/math/math.h +++ b/math/math.h @@ -354,10 +354,10 @@ extern int matherr __P ((struct exception *__exc)); /* Return nonzero value if arguments are unordered. */ # ifndef isunordered -# define isunordered(x, y) \ +# define isunordered(u, v) \ (__extension__ \ - ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ - fpclassify (__x) == FP_NAN || fpclassify (__y) == FP_NAN; })) + ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \ + fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; })) # endif #endif diff --git a/math/test-fenv.c b/math/test-fenv.c index ab09410..3a5a7ed 100644 --- a/math/test-fenv.c +++ b/math/test-fenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997 Free Software Foundation, Inc. +/* Copyright (C) 1997, 1998 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de> and Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -117,28 +117,29 @@ static void print_rounding (int rounding) { - switch (rounding) { + switch (rounding) + { #ifdef FE_TONEAREST - case FE_TONEAREST: - printf ("TONEAREST"); - break; + case FE_TONEAREST: + printf ("TONEAREST"); + break; #endif #ifdef FE_UPWARD - case FE_UPWARD: - printf ("UPWARD"); - break; + case FE_UPWARD: + printf ("UPWARD"); + break; #endif #ifdef FE_DOWNWARD - case FE_DOWNWARD: - printf ("DOWNWARD"); - break; + case FE_DOWNWARD: + printf ("DOWNWARD"); + break; #endif #ifdef FE_TOWARDZERO - case FE_TOWARDZERO: - printf ("TOWARDZERO"); - break; + case FE_TOWARDZERO: + printf ("TOWARDZERO"); + break; #endif - } + } printf (".\n"); } @@ -154,11 +155,12 @@ test_rounding (const char *test_name, int rounding_mode) printf (" Pass: Rounding mode is "); print_rounding (curr_rounding); } - else { - ++count_errors; - printf (" Fail: Rounding mode is "); - print_rounding (curr_rounding); - } + else + { + ++count_errors; + printf (" Fail: Rounding mode is "); + print_rounding (curr_rounding); + } } @@ -247,7 +249,7 @@ feenv_nomask_test (const char *flag_name, int fe_exc) printf ("Test: after fesetenv (FE_NOMASK_ENV) processes will abort\n"); printf (" when feraiseexcept (%s) is called.\n", flag_name); - pid = fork (); + pid = fork (); if (pid == 0) { #ifdef RLIMIT_CORE |