1/*- 2 * Copyright (c) 2008 David Schultz <das@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 27/* 28 * Tests for corner cases in the inverse trigonometric functions. Some 29 * accuracy tests are included as well, but these are very basic 30 * sanity checks, not intended to be comprehensive. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-invtrig.c 251241 2013-06-02 04:30:03Z das $"); |
35 36#include <assert.h> 37#include <fenv.h> 38#include <float.h> 39#include <math.h> 40#include <stdio.h> 41 |
42#include "test-utils.h" |
43 44#define LEN(a) (sizeof(a) / sizeof((a)[0])) 45 46#pragma STDC FENV_ACCESS ON 47 48/* 49 * Test that a function returns the correct value and sets the 50 * exception flags correctly. A tolerance specifying the maximum 51 * relative error allowed may be specified. For the 'testall' 52 * functions, the tolerance is specified in ulps. 53 * 54 * These are macros instead of functions so that assert provides more 55 * meaningful error messages. 56 */ 57#define test_tol(func, x, result, tol, excepts) do { \ 58 volatile long double _in = (x), _out = (result); \ 59 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \ |
60 assert(fpequal_tol(func(_in), _out, (tol), CS_BOTH)); \ 61 assert(((void)func, fetestexcept(ALL_STD_EXCEPT) == (excepts))); \ |
62} while (0) 63#define test(func, x, result, excepts) \ 64 test_tol(func, (x), (result), 0, (excepts)) 65 66#define testall_tol(prefix, x, result, tol, excepts) do { \ 67 test_tol(prefix, (double)(x), (double)(result), \ 68 (tol) * ldexp(1.0, 1 - DBL_MANT_DIG), (excepts)); \ 69 test_tol(prefix##f, (float)(x), (float)(result), \ 70 (tol) * ldexpf(1.0, 1 - FLT_MANT_DIG), (excepts)); \ 71 test_tol(prefix##l, (x), (result), \ 72 (tol) * ldexpl(1.0, 1 - LDBL_MANT_DIG), (excepts)); \ 73} while (0) 74#define testall(prefix, x, result, excepts) \ 75 testall_tol(prefix, (x), (result), 0, (excepts)) 76 77#define test2_tol(func, y, x, result, tol, excepts) do { \ 78 volatile long double _iny = (y), _inx = (x), _out = (result); \ 79 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \ |
80 assert(fpequal_tol(func(_iny, _inx), _out, (tol), CS_BOTH)); \ 81 assert(((void)func, fetestexcept(ALL_STD_EXCEPT) == (excepts))); \ |
82} while (0) 83#define test2(func, y, x, result, excepts) \ 84 test2_tol(func, (y), (x), (result), 0, (excepts)) 85 86#define testall2_tol(prefix, y, x, result, tol, excepts) do { \ 87 test2_tol(prefix, (double)(y), (double)(x), (double)(result), \ 88 (tol) * ldexp(1.0, 1 - DBL_MANT_DIG), (excepts)); \ 89 test2_tol(prefix##f, (float)(y), (float)(x), (float)(result), \ --- 8 unchanged lines hidden (view full) --- 98pi = 3.14159265358979323846264338327950280e+00L, 99pio3 = 1.04719755119659774615421446109316766e+00L, 100c3pi = 9.42477796076937971538793014983850839e+00L, 101c5pi = 1.57079632679489661923132169163975140e+01L, 102c7pi = 2.19911485751285526692385036829565196e+01L, 103c5pio3 = 5.23598775598298873077107230546583851e+00L, 104sqrt2m1 = 4.14213562373095048801688724209698081e-01L; 105 |
106 |
107/* 108 * Test special case inputs in asin(), acos() and atan(): signed 109 * zeroes, infinities, and NaNs. 110 */ 111static void 112test_special(void) 113{ 114 --- 344 unchanged lines hidden --- |