(linenum→info "unix/slp.c:2238")

glibc/2.7/math/libm-test.inc

    1: /* Copyright (C) 1997-2006, 2007 Free Software Foundation, Inc.
    2:    This file is part of the GNU C Library.
    3:    Contributed by Andreas Jaeger <aj@suse.de>, 1997.
    4: 
    5:    The GNU C Library is free software; you can redistribute it and/or
    6:    modify it under the terms of the GNU Lesser General Public
    7:    License as published by the Free Software Foundation; either
    8:    version 2.1 of the License, or (at your option) any later version.
    9: 
   10:    The GNU C Library is distributed in the hope that it will be useful,
   11:    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13:    Lesser General Public License for more details.
   14: 
   15:    You should have received a copy of the GNU Lesser General Public
   16:    License along with the GNU C Library; if not, write to the Free
   17:    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   18:    02111-1307 USA.  */
   19: 
   20: /* Part of testsuite for libm.
   21: 
   22:    This file is processed by a perl script.  The resulting file has to
   23:    be included by a master file that defines:
   24: 
   25:    Macros:
   26:    FUNC(function): converts general function name (like cos) to
   27:    name with correct suffix (e.g. cosl or cosf)
   28:    MATHCONST(x):   like FUNC but for constants (e.g convert 0.0 to 0.0L)
   29:    FLOAT:          floating point type to test
   30:    - TEST_MSG:     informal message to be displayed
   31:    CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat):
   32:    chooses one of the parameters as delta for testing
   33:    equality
   34:    PRINTF_EXPR     Floating point conversion specification to print a variable
   35:    of type FLOAT with printf.  PRINTF_EXPR just contains
   36:    the specifier, not the percent and width arguments,
   37:    e.g. "f".
   38:    PRINTF_XEXPR    Like PRINTF_EXPR, but print in hexadecimal format.
   39:    PRINTF_NEXPR Like PRINTF_EXPR, but print nice.  */
   40: 
   41: /* This testsuite has currently tests for:
   42:    acos, acosh, asin, asinh, atan, atan2, atanh,
   43:    cbrt, ceil, copysign, cos, cosh, erf, erfc, exp, exp10, exp2, expm1,
   44:    fabs, fdim, floor, fma, fmax, fmin, fmod, fpclassify,
   45:    frexp, gamma, hypot,
   46:    ilogb, isfinite, isinf, isnan, isnormal,
   47:    isless, islessequal, isgreater, isgreaterequal, islessgreater, isunordered,
   48:    j0, j1, jn,
   49:    ldexp, lgamma, log, log10, log1p, log2, logb,
   50:    modf, nearbyint, nextafter,
   51:    pow, remainder, remquo, rint, lrint, llrint,
   52:    round, lround, llround,
   53:    scalb, scalbn, scalbln, signbit, sin, sincos, sinh, sqrt, tan, tanh, tgamma, trunc,
   54:    y0, y1, yn, significand
   55: 
   56:    and for the following complex math functions:
   57:    cabs, cacos, cacosh, carg, casin, casinh, catan, catanh,
   58:    ccos, ccosh, cexp, clog, cpow, cproj, csin, csinh, csqrt, ctan, ctanh.
   59: 
   60:    At the moment the following functions aren't tested:
   61:    drem, nan
   62: 
   63:    Parameter handling is primitive in the moment:
   64:    --verbose=[0..3] for different levels of output:
   65:    0: only error count
   66:    1: basic report on failed tests (default)
   67:    2: full report on all tests
   68:    -v for full output (equals --verbose=3)
   69:    -u for generation of an ULPs file
   70:  */
   71: 
   72: /* "Philosophy":
   73: 
   74:    This suite tests some aspects of the correct implementation of
   75:    mathematical functions in libm.  Some simple, specific parameters
   76:    are tested for correctness but there's no exhaustive
   77:    testing.  Handling of specific inputs (e.g. infinity, not-a-number)
   78:    is also tested.  Correct handling of exceptions is checked
   79:    against.  These implemented tests should check all cases that are
   80:    specified in ISO C99.
   81: 
   82:    Exception testing: At the moment only divide-by-zero and invalid
   83:    exceptions are tested.  Overflow/underflow and inexact exceptions
   84:    aren't checked at the moment.
   85: 
   86:    NaN values: There exist signalling and quiet NaNs.  This implementation
   87:    only uses quiet NaN as parameter but does not differenciate
   88:    between the two kinds of NaNs as result.
   89: 
   90:    Inline functions: Inlining functions should give an improvement in
   91:    speed - but not in precission.  The inlined functions return
   92:    reasonable values for a reasonable range of input values.  The
   93:    result is not necessarily correct for all values and exceptions are
   94:    not correctly raised in all cases.  Problematic input and return
   95:    values are infinity, not-a-number and minus zero.  This suite
   96:    therefore does not check these specific inputs and the exception
   97:    handling for inlined mathematical functions - just the "reasonable"
   98:    values are checked.
   99: 
  100:    Beware: The tests might fail for any of the following reasons:
  101:    - Tests are wrong
  102:    - Functions are wrong
  103:    - Floating Point Unit not working properly
  104:    - Compiler has errors
  105: 
  106:    With e.g. gcc 2.7.2.2 the test for cexp fails because of a compiler error.
  107: 
  108: 
  109:    To Do: All parameter should be numbers that can be represented as
  110:    exact floating point values.  Currently some values cannot be
  111:    represented exactly and therefore the result is not the expected
  112:    result.  For this we will use 36 digits so that numbers can be
  113:    represented exactly.  */
  114: 
  115: #ifndef _GNU_SOURCE
  116: # define _GNU_SOURCE
  117: #endif
  118: 
  119: #include "libm-test-ulps.h"
  120: #include <complex.h>
  121: #include <math.h>
  122: #include <float.h>
  123: #include <fenv.h>
  124: #include <limits.h>
  125: 
  126: #include <errno.h>
  127: #include <stdlib.h>
  128: #include <stdio.h>
  129: #include <string.h>
  130: #include <argp.h>
  131: 
  132: /* Possible exceptions */
  133: #define NO_EXCEPTION                    0x0
  134: #define INVALID_EXCEPTION               0x1
  135: #define DIVIDE_BY_ZERO_EXCEPTION        0x2
  136: /* The next flags signals that those exceptions are allowed but not required.   */
  137: #define INVALID_EXCEPTION_OK            0x4
  138: #define DIVIDE_BY_ZERO_EXCEPTION_OK     0x8
  139: #define EXCEPTIONS_OK INVALID_EXCEPTION_OK+DIVIDE_BY_ZERO_EXCEPTION_OK
  140: /* Some special test flags, passed togther with exceptions.  */
  141: #define IGNORE_ZERO_INF_SIGN            0x10
  142: 
  143: /* Various constants (we must supply them precalculated for accuracy).  */
  144: #define M_PI_6l                 .52359877559829887307710723054658383L
  145: #define M_E2l                   7.389056098930650227230427460575008L
  146: #define M_E3l                   20.085536923187667740928529654581719L
  147: #define M_2_SQRT_PIl            3.5449077018110320545963349666822903L     /* 2 sqrt (M_PIl)  */
  148: #define M_SQRT_PIl              1.7724538509055160272981674833411451L       /* sqrt (M_PIl)  */
  149: #define M_LOG_SQRT_PIl          0.57236494292470008707171367567652933L  /* log(sqrt(M_PIl))  */
  150: #define M_LOG_2_SQRT_PIl        1.265512123484645396488945797134706L   /* log(2*sqrt(M_PIl))  */
  151: #define M_PI_34l                (M_PIl - M_PI_4l)             /* 3*pi/4 */
  152: #define M_PI_34_LOG10El         (M_PIl - M_PI_4l) * M_LOG10El
  153: #define M_PI2_LOG10El           M_PI_2l * M_LOG10El
  154: #define M_PI4_LOG10El           M_PI_4l * M_LOG10El
  155: #define M_PI_LOG10El            M_PIl * M_LOG10El
  156: #define M_SQRT_2_2              0.70710678118654752440084436210484903L /* sqrt (2) / 2 */
  157: 
  158: static FILE *ulps_file; /* File to document difference.  */
  159: static int output_ulps; /* Should ulps printed?  */
  160: 
  161: static int noErrors;    /* number of errors */
  162: static int noTests;     /* number of tests (without testing exceptions) */
  163: static int noExcTests;  /* number of tests for exception flags */
  164: static int noXFails;    /* number of expected failures.  */
  165: static int noXPasses;   /* number of unexpected passes.  */
  166: 
  167: static int verbose;
  168: static int output_max_error;    /* Should the maximal errors printed?  */
  169: static int output_points;       /* Should the single function results printed?  */
  170: static int ignore_max_ulp;      /* Should we ignore max_ulp?  */
  171: 
  172: static FLOAT minus_zero, plus_zero;
  173: static FLOAT plus_infty, minus_infty, nan_value, max_value, min_value;
  174: 
  175: static FLOAT max_error, real_max_error, imag_max_error;
  176: 
  177: 
  178: #define BUILD_COMPLEX(real, imag) \
  179:   ({ __complex__ FLOAT __retval;                                              \
  180:      __real__ __retval = (real);                                              \
  181:      __imag__ __retval = (imag);                                              \
  182:      __retval; })
  183: 
  184: #define BUILD_COMPLEX_INT(real, imag) \
  185:   ({ __complex__ int __retval;                                                \
  186:      __real__ __retval = (real);                                              \
  187:      __imag__ __retval = (imag);                                              \
  188:      __retval; })
  189: 
  190: 
  191: #define MANT_DIG CHOOSE ((LDBL_MANT_DIG-1), (DBL_MANT_DIG-1), (FLT_MANT_DIG-1),  \
  192:                          (LDBL_MANT_DIG-1), (DBL_MANT_DIG-1), (FLT_MANT_DIG-1))
  193: 
  194: static void
  195: init_max_error (void)
  196: {
  197:   max_error = 0;
  198:   real_max_error = 0;
  199:   imag_max_error = 0;
  200:   feclearexcept (FE_ALL_EXCEPT);
  201: }
  202: 
  203: static void
  204: set_max_error (FLOAT current, FLOAT *curr_max_error)
  205: {
  206:   if (current > *curr_max_error)
  207:     *curr_max_error = current;
  208: }
  209: 
  210: 
  211: /* Should the message print to screen?  This depends on the verbose flag,
  212:    and the test status.  */
  213: static int
  214: print_screen (int ok, int xfail)
  215: {
  216:   if (output_points
  217:       && (verbose > 1
  218:           || (verbose == 1 && ok == xfail)))
  219:     return 1;
  220:   return 0;
  221: }
  222: 
  223: 
  224: /* Should the message print to screen?  This depends on the verbose flag,
  225:    and the test status.  */
  226: static int
  227: print_screen_max_error (int ok, int xfail)
  228: {
  229:   if (output_max_error
  230:       && (verbose > 1
  231:           || ((verbose == 1) && (ok == xfail))))
  232:     return 1;
  233:   return 0;
  234: }
  235: 
  236: /* Update statistic counters.  */
  237: static void
  238: update_stats (int ok, int xfail)
  239: {
  240:   ++noTests;
  241:   if (ok && xfail)
  242:     ++noXPasses;
  243:   else if (!ok && xfail)
  244:     ++noXFails;
  245:   else if (!ok && !xfail)
  246:     ++noErrors;
  247: }
  248: 
  249: static void
  250: print_ulps (const char *test_name, FLOAT ulp)
  251: {
  252:   if (output_ulps)
  253:     {
  254:       fprintf (ulps_file, "Test \"%s\":\n", test_name);
  255:       fprintf (ulps_file, "%s: %.0" PRINTF_NEXPR "\n",
  256:                CHOOSE("ldouble", "double", "float",
  257:                       "ildouble", "idouble", "ifloat"),
  258:                FUNC(ceil) (ulp));
  259:     }
  260: }
  261: 
  262: static void
  263: print_function_ulps (const char *function_name, FLOAT ulp)
  264: {
  265:   if (output_ulps)
  266:     {
  267:       fprintf (ulps_file, "Function: \"%s\":\n", function_name);
  268:       fprintf (ulps_file, "%s: %.0" PRINTF_NEXPR "\n",
  269:                CHOOSE("ldouble", "double", "float",
  270:                       "ildouble", "idouble", "ifloat"),
  271:                FUNC(ceil) (ulp));
  272:     }
  273: }
  274: 
  275: 
  276: static void
  277: print_complex_function_ulps (const char *function_name, FLOAT real_ulp,
  278:                              FLOAT imag_ulp)
  279: {
  280:   if (output_ulps)
  281:     {
  282:       if (real_ulp != 0.0)
  283:         {
  284:           fprintf (ulps_file, "Function: Real part of \"%s\":\n", function_name);
  285:           fprintf (ulps_file, "%s: %.0" PRINTF_NEXPR "\n",
  286:                    CHOOSE("ldouble", "double", "float",
  287:                           "ildouble", "idouble", "ifloat"),
  288:                    FUNC(ceil) (real_ulp));
  289:         }
  290:       if (imag_ulp != 0.0)
  291:         {
  292:           fprintf (ulps_file, "Function: Imaginary part of \"%s\":\n", function_name);
  293:           fprintf (ulps_file, "%s: %.0" PRINTF_NEXPR "\n",
  294:                    CHOOSE("ldouble", "double", "float",
  295:                           "ildouble", "idouble", "ifloat"),
  296:                    FUNC(ceil) (imag_ulp));
  297:         }
  298: 
  299: 
  300:     }
  301: }
  302: 
  303: 
  304: 
  305: /* Test if Floating-Point stack hasn't changed */
  306: static void
  307: fpstack_test (const char *test_name)
  308: {
  309: #ifdef i386
  310:   static int old_stack;
  311:   int sw;
  312: 
  313:   asm ("fnstsw" : "=a" (sw));
  314:   sw >>= 11;
  315:   sw &= 7;
  316: 
  317:   if (sw != old_stack)
  318:     {
  319:       printf ("FP-Stack wrong after test %s (%d, should be %d)\n",
  320:               test_name, sw, old_stack);
  321:       ++noErrors;
  322:       old_stack = sw;
  323:     }
  324: #endif
  325: }
  326: 
  327: 
  328: static void
  329: print_max_error (const char *func_name, FLOAT allowed, int xfail)
  330: {
  331:   int ok = 0;
  332: 
  333:   if (max_error == 0.0 || (max_error <= allowed && !ignore_max_ulp))
  334:     {
  335:       ok = 1;
  336:     }
  337: 
  338:   if (!ok)
  339:     print_function_ulps (func_name, max_error);
  340: 
  341: 
  342:   if (print_screen_max_error (ok, xfail))
  343:     {
  344:       printf ("Maximal error of `%s'\n", func_name);
  345:       printf (" is      : %.0" PRINTF_NEXPR " ulp\n", FUNC(ceil) (max_error));
  346:       printf (" accepted: %.0" PRINTF_NEXPR " ulp\n", FUNC(ceil) (allowed));
  347:     }
  348: 
  349:   update_stats (ok, xfail);
  350: }
  351: 
  352: 
  353: static void
  354: print_complex_max_error (const char *func_name, __complex__ FLOAT allowed,
  355:                          __complex__ int xfail)
  356: {
  357:   int ok = 0;
  358: 
  359:   if ((real_max_error == 0 && imag_max_error == 0)
  360:       || (real_max_error <= __real__ allowed
  361:           && imag_max_error <= __imag__ allowed
  362:           && !ignore_max_ulp))
  363:     {
  364:       ok = 1;
  365:     }
  366: 
  367:   if (!ok)
  368:     print_complex_function_ulps (func_name, real_max_error, imag_max_error);
  369: 
  370: 
  371:   if (print_screen_max_error (ok, xfail))
  372:     {
  373:       printf ("Maximal error of real part of: %s\n", func_name);
  374:       printf (" is      : %.0" PRINTF_NEXPR " ulp\n",
  375:               FUNC(ceil) (real_max_error));
  376:       printf (" accepted: %.0" PRINTF_NEXPR " ulp\n",
  377:               FUNC(ceil) (__real__ allowed));
  378:       printf ("Maximal error of imaginary part of: %s\n", func_name);
  379:       printf (" is      : %.0" PRINTF_NEXPR " ulp\n",
  380:               FUNC(ceil) (imag_max_error));
  381:       printf (" accepted: %.0" PRINTF_NEXPR " ulp\n",
  382:               FUNC(ceil) (__imag__ allowed));
  383:     }
  384: 
  385:   update_stats (ok, xfail);
  386: }
  387: 
  388: 
  389: /* Test whether a given exception was raised.  */
  390: static void
  391: test_single_exception (const char *test_name,
  392:                        int exception,
  393:                        int exc_flag,
  394:                        int fe_flag,
  395:                        const char *flag_name)
  396: {
  397: #ifndef TEST_INLINE
  398:   int ok = 1;
  399:   if (exception & exc_flag)
  400:     {
  401:       if (fetestexcept (fe_flag))
  402:         {
  403:           if (print_screen (1, 0))
  404:             printf ("Pass: %s: Exception \"%s\" set\n", test_name, flag_name);
  405:         }
  406:       else
  407:         {
  408:           ok = 0;
  409:           if (print_screen (0, 0))
  410:             printf ("Failure: %s: Exception \"%s\" not set\n",
  411:                     test_name, flag_name);
  412:         }
  413:     }
  414:   else
  415:     {
  416:       if (fetestexcept (fe_flag))
  417:         {
  418:           ok = 0;
  419:           if (print_screen (0, 0))
  420:             printf ("Failure: %s: Exception \"%s\" set\n",
  421:                     test_name, flag_name);
  422:         }
  423:       else
  424:         {
  425:           if (print_screen (1, 0))
  426:             printf ("%s: Exception \"%s\" not set\n", test_name,
  427:                     flag_name);
  428:         }
  429:     }
  430:   if (!ok)
  431:     ++noErrors;
  432: 
  433: #endif
  434: }
  435: 
  436: 
  437: /* Test whether exceptions given by EXCEPTION are raised.  Ignore thereby
  438:    allowed but not required exceptions.
  439: */
  440: static void
  441: test_exceptions (const char *test_name, int exception)
  442: {
  443:   ++noExcTests;
  444: #ifdef FE_DIVBYZERO
  445:   if ((exception & DIVIDE_BY_ZERO_EXCEPTION_OK) == 0)
  446:     test_single_exception (test_name, exception,
  447:                            DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
  448:                            "Divide by zero");
  449: #endif
  450: #ifdef FE_INVALID
  451:   if ((exception & INVALID_EXCEPTION_OK) == 0)
  452:     test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
  453:                          "Invalid operation");
  454: #endif
  455:   feclearexcept (FE_ALL_EXCEPT);
  456: }
  457: 
  458: 
  459: static void
  460: check_float_internal (const char *test_name, FLOAT computed, FLOAT expected,
  461:                       FLOAT max_ulp, int xfail, int exceptions,
  462:                       FLOAT *curr_max_error)
  463: {
  464:   int ok = 0;
  465:   int print_diff = 0;
  466:   FLOAT diff = 0;
  467:   FLOAT ulp = 0;
  468: 
  469:   test_exceptions (test_name, exceptions);
  470:   if (isnan (computed) && isnan (expected))
  471:     ok = 1;
  472:   else if (isinf (computed) && isinf (expected))
  473:     {
  474:       /* Test for sign of infinities.  */
  475:       if ((exceptions & IGNORE_ZERO_INF_SIGN) == 0
  476:           && signbit (computed) != signbit (expected))
  477:         {
  478:           ok = 0;
  479:           printf ("infinity has wrong sign.\n");
  480:         }
  481:       else
  482:         ok = 1;
  483:     }
  484:   /* Don't calc ulp for NaNs or infinities.  */
  485:   else if (isinf (computed) || isnan (computed) || isinf (expected) || isnan (expected))
  486:     ok = 0;
  487:   else
  488:     {
  489:       diff = FUNC(fabs) (computed - expected);
  490:       /* ilogb (0) isn't allowed.  */
  491:       if (expected == 0.0)
  492:         ulp = diff / FUNC(ldexp) (1.0, - MANT_DIG);
  493:       else
  494:         ulp = diff / FUNC(ldexp) (1.0, FUNC(ilogb) (expected) - MANT_DIG);
  495:       set_max_error (ulp, curr_max_error);
  496:       print_diff = 1;
  497:       if ((exceptions & IGNORE_ZERO_INF_SIGN) == 0
  498:           && computed == 0.0 && expected == 0.0
  499:           && signbit(computed) != signbit (expected))
  500:         ok = 0;
  501:       else if (ulp <= 0.5 || (ulp <= max_ulp && !ignore_max_ulp))
  502:         ok = 1;
  503:       else
  504:         {
  505:           ok = 0;
  506:           print_ulps (test_name, ulp);
  507:         }
  508: 
  509:     }
  510:   if (print_screen (ok, xfail))
  511:     {
  512:       if (!ok)
  513:         printf ("Failure: ");
  514:       printf ("Test: %s\n", test_name);
  515:       printf ("Result:\n");
  516:       printf (" is:         % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
  517:               computed, computed);
  518:       printf (" should be:  % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
  519:               expected, expected);
  520:       if (print_diff)
  521:         {
  522:           printf (" difference: % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR
  523:                   "\n", diff, diff);
  524:           printf (" ulp       : % .4" PRINTF_NEXPR "\n", ulp);
  525:           printf (" max.ulp   : % .4" PRINTF_NEXPR "\n", max_ulp);
  526:         }
  527:     }
  528:   update_stats (ok, xfail);
  529: 
  530:   fpstack_test (test_name);
  531: }
  532: 
  533: 
  534: static void
  535: check_float (const char *test_name, FLOAT computed, FLOAT expected,
  536:              FLOAT max_ulp, int xfail, int exceptions)
  537: {
  538:   check_float_internal (test_name, computed, expected, max_ulp, xfail,
  539:                         exceptions, &max_error);
  540: }
  541: 
  542: 
  543: static void
  544: check_complex (const char *test_name, __complex__ FLOAT computed,
  545:                __complex__ FLOAT expected,
  546:                __complex__ FLOAT max_ulp, __complex__ int xfail,
  547:                int exception)
  548: {
  549:   FLOAT part_comp, part_exp, part_max_ulp;
  550:   int part_xfail;
  551:   char str[200];
  552: 
  553:   sprintf (str, "Real part of: %s", test_name);
  554:   part_comp = __real__ computed;
  555:   part_exp = __real__ expected;
  556:   part_max_ulp = __real__ max_ulp;
  557:   part_xfail = __real__ xfail;
  558: 
  559:   check_float_internal (str, part_comp, part_exp, part_max_ulp, part_xfail,
  560:                         exception, &real_max_error);
  561: 
  562:   sprintf (str, "Imaginary part of: %s", test_name);
  563:   part_comp = __imag__ computed;
  564:   part_exp = __imag__ expected;
  565:   part_max_ulp = __imag__ max_ulp;
  566:   part_xfail = __imag__ xfail;
  567: 
  568:   /* Don't check again for exceptions, just pass through the
  569:      zero/inf sign test.  */
  570:   check_float_internal (str, part_comp, part_exp, part_max_ulp, part_xfail,
  571:                         exception & IGNORE_ZERO_INF_SIGN,
  572:                         &imag_max_error);
  573: }
  574: 
  575: 
  576: /* Check that computed and expected values are equal (int values).  */
  577: static void
  578: check_int (const char *test_name, int computed, int expected, int max_ulp,
  579:            int xfail, int exceptions)
  580: {
  581:   int diff = computed - expected;
  582:   int ok = 0;
  583: 
  584:   test_exceptions (test_name, exceptions);
  585:   noTests++;
  586:   if (abs (diff) <= max_ulp)
  587:     ok = 1;
  588: 
  589:   if (!ok)
  590:     print_ulps (test_name, diff);
  591: 
  592:   if (print_screen (ok, xfail))
  593:     {
  594:       if (!ok)
  595:         printf ("Failure: ");
  596:       printf ("Test: %s\n", test_name);
  597:       printf ("Result:\n");
  598:       printf (" is:         %d\n", computed);
  599:       printf (" should be:  %d\n", expected);
  600:     }
  601: 
  602:   update_stats (ok, xfail);
  603:   fpstack_test (test_name);
  604: }
  605: 
  606: 
  607: /* Check that computed and expected values are equal (long int values).  */
  608: static void
  609: check_long (const char *test_name, long int computed, long int expected,
  610:             long int max_ulp, int xfail, int exceptions)
  611: {
  612:   long int diff = computed - expected;
  613:   int ok = 0;
  614: 
  615:   test_exceptions (test_name, exceptions);
  616:   noTests++;
  617:   if (labs (diff) <= max_ulp)
  618:     ok = 1;
  619: 
  620:   if (!ok)
  621:     print_ulps (test_name, diff);
  622: 
  623:   if (print_screen (ok, xfail))
  624:     {
  625:       if (!ok)
  626:         printf ("Failure: ");
  627:       printf ("Test: %s\n", test_name);
  628:       printf ("Result:\n");
  629:       printf (" is:         %ld\n", computed);
  630:       printf (" should be:  %ld\n", expected);
  631:     }
  632: 
  633:   update_stats (ok, xfail);
  634:   fpstack_test (test_name);
  635: }
  636: 
  637: 
  638: /* Check that computed value is true/false.  */
  639: static void
  640: check_bool (const char *test_name, int computed, int expected,
  641:             long int max_ulp, int xfail, int exceptions)
  642: {
  643:   int ok = 0;
  644: 
  645:   test_exceptions (test_name, exceptions);
  646:   noTests++;
  647:   if ((computed == 0) == (expected == 0))
  648:     ok = 1;
  649: 
  650:   if (print_screen (ok, xfail))
  651:     {
  652:       if (!ok)
  653:         printf ("Failure: ");
  654:       printf ("Test: %s\n", test_name);
  655:       printf ("Result:\n");
  656:       printf (" is:         %d\n", computed);
  657:       printf (" should be:  %d\n", expected);
  658:     }
  659: 
  660:   update_stats (ok, xfail);
  661:   fpstack_test (test_name);
  662: }
  663: 
  664: 
  665: /* check that computed and expected values are equal (long int values) */
  666: static void
  667: check_longlong (const char *test_name, long long int computed,
  668:                 long long int expected,
  669:                 long long int max_ulp, int xfail,
  670:                 int exceptions)
  671: {
  672:   long long int diff = computed - expected;
  673:   int ok = 0;
  674: 
  675:   test_exceptions (test_name, exceptions);
  676:   noTests++;
  677:   if (llabs (diff) <= max_ulp)
  678:     ok = 1;
  679: 
  680:   if (!ok)
  681:     print_ulps (test_name, diff);
  682: 
  683:   if (print_screen (ok, xfail))
  684:     {
  685:       if (!ok)
  686:         printf ("Failure:");
  687:       printf ("Test: %s\n", test_name);
  688:       printf ("Result:\n");
  689:       printf (" is:         %lld\n", computed);
  690:       printf (" should be:  %lld\n", expected);
  691:     }
  692: 
  693:   update_stats (ok, xfail);
  694:   fpstack_test (test_name);
  695: }
  696: 
  697: 
  698: 
  699: /* This is to prevent messages from the SVID libm emulation.  */
  700: int
  701: matherr (struct exception *x __attribute__ ((unused)))
  702: {
  703:   return 1;
  704: }
  705: 
  706: 
  707: /****************************************************************************
  708:   Tests for single functions of libm.
  709:   Please keep them alphabetically sorted!
  710: ****************************************************************************/
  711: 
  712: static void
  713: acos_test (void)
  714: {
  715:   errno = 0;
  716:   FUNC(acos) (0);
  717:   if (errno == ENOSYS)
  718:     /* Function not implemented.  */
  719:     return;
  720: 
  721:   START (acos);
  722: 
  723:   TEST_f_f (acos, plus_infty, nan_value, INVALID_EXCEPTION);
  724:   TEST_f_f (acos, minus_infty, nan_value, INVALID_EXCEPTION);
  725:   TEST_f_f (acos, nan_value, nan_value);
  726: 
  727:   /* |x| > 1: */
  728:   TEST_f_f (acos, 1.125L, nan_value, INVALID_EXCEPTION);
  729:   TEST_f_f (acos, -1.125L, nan_value, INVALID_EXCEPTION);
  730: 
  731:   TEST_f_f (acos, 0, M_PI_2l);
  732:   TEST_f_f (acos, minus_zero, M_PI_2l);
  733:   TEST_f_f (acos, 1, 0);
  734:   TEST_f_f (acos, -1, M_PIl);
  735:   TEST_f_f (acos, 0.5, M_PI_6l*2.0);
  736:   TEST_f_f (acos, -0.5, M_PI_6l*4.0);
  737:   TEST_f_f (acos, 0.75L, 0.722734247813415611178377352641333362L);
  738:   TEST_f_f (acos, 2e-17L, 1.57079632679489659923132169163975144L);
  739:   TEST_f_f (acos, 0.0625L, 1.50825556499840522843072005474337068L);
  740:   END (acos);
  741: }
  742: 
  743: static void
  744: acosh_test (void)
  745: {
  746:   errno = 0;
  747:   FUNC(acosh) (7);
  748:   if (errno == ENOSYS)
  749:     /* Function not implemented.  */
  750:     return;
  751: 
  752:   START (acosh);
  753: 
  754:   TEST_f_f (acosh, plus_infty, plus_infty);
  755:   TEST_f_f (acosh, minus_infty, nan_value, INVALID_EXCEPTION);
  756: 
  757:   /* x < 1:  */
  758:   TEST_f_f (acosh, -1.125L, nan_value, INVALID_EXCEPTION);
  759: 
  760:   TEST_f_f (acosh, 1, 0);
  761:   TEST_f_f (acosh, 7, 2.63391579384963341725009269461593689L);
  762: 
  763:   END (acosh);
  764: }
  765: 
  766: static void
  767: asin_test (void)
  768: {
  769:   errno = 0;
  770:   FUNC(asin) (0);
  771:   if (errno == ENOSYS)
  772:     /* Function not implemented.  */
  773:     return;
  774: 
  775:   START (asin);
  776: 
  777:   TEST_f_f (asin, plus_infty, nan_value, INVALID_EXCEPTION);
  778:   TEST_f_f (asin, minus_infty, nan_value, INVALID_EXCEPTION);
  779:   TEST_f_f (asin, nan_value, nan_value);
  780: 
  781:   /* asin x == NaN plus invalid exception for |x| > 1.  */
  782:   TEST_f_f (asin, 1.125L, nan_value, INVALID_EXCEPTION);
  783:   TEST_f_f (asin, -1.125L, nan_value, INVALID_EXCEPTION);
  784: 
  785:   TEST_f_f (asin, 0, 0);
  786:   TEST_f_f (asin, minus_zero, minus_zero);
  787:   TEST_f_f (asin, 0.5, M_PI_6l);
  788:   TEST_f_f (asin, -0.5, -M_PI_6l);
  789:   TEST_f_f (asin, 1.0, M_PI_2l);
  790:   TEST_f_f (asin, -1.0, -M_PI_2l);
  791:   TEST_f_f (asin, 0.75L, 0.848062078981481008052944338998418080L);
  792: 
  793:   END (asin);
  794: }
  795: 
  796: static void
  797: asinh_test (void)