Deleted Added
full compact
test-invtrig.c (216222) test-invtrig.c (251241)
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>
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 216222 2010-12-06 00:02:49Z das $");
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
35
36#include <assert.h>
37#include <fenv.h>
38#include <float.h>
39#include <math.h>
40#include <stdio.h>
41
42#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
43 FE_OVERFLOW | FE_UNDERFLOW)
42#include "test-utils.h"
44
45#define LEN(a) (sizeof(a) / sizeof((a)[0]))
46
47#pragma STDC FENV_ACCESS ON
48
49/*
50 * Test that a function returns the correct value and sets the
51 * exception flags correctly. A tolerance specifying the maximum
52 * relative error allowed may be specified. For the 'testall'
53 * functions, the tolerance is specified in ulps.
54 *
55 * These are macros instead of functions so that assert provides more
56 * meaningful error messages.
57 */
58#define test_tol(func, x, result, tol, excepts) do { \
59 volatile long double _in = (x), _out = (result); \
60 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
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); \
61 assert(fpequal(func(_in), _out, (tol))); \
62 assert((func, fetestexcept(ALL_STD_EXCEPT) == (excepts))); \
60 assert(fpequal_tol(func(_in), _out, (tol), CS_BOTH)); \
61 assert(((void)func, fetestexcept(ALL_STD_EXCEPT) == (excepts))); \
63} while (0)
64#define test(func, x, result, excepts) \
65 test_tol(func, (x), (result), 0, (excepts))
66
67#define testall_tol(prefix, x, result, tol, excepts) do { \
68 test_tol(prefix, (double)(x), (double)(result), \
69 (tol) * ldexp(1.0, 1 - DBL_MANT_DIG), (excepts)); \
70 test_tol(prefix##f, (float)(x), (float)(result), \
71 (tol) * ldexpf(1.0, 1 - FLT_MANT_DIG), (excepts)); \
72 test_tol(prefix##l, (x), (result), \
73 (tol) * ldexpl(1.0, 1 - LDBL_MANT_DIG), (excepts)); \
74} while (0)
75#define testall(prefix, x, result, excepts) \
76 testall_tol(prefix, (x), (result), 0, (excepts))
77
78#define test2_tol(func, y, x, result, tol, excepts) do { \
79 volatile long double _iny = (y), _inx = (x), _out = (result); \
80 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
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); \
81 assert(fpequal(func(_iny, _inx), _out, (tol))); \
82 assert((func, fetestexcept(ALL_STD_EXCEPT) == (excepts))); \
80 assert(fpequal_tol(func(_iny, _inx), _out, (tol), CS_BOTH)); \
81 assert(((void)func, fetestexcept(ALL_STD_EXCEPT) == (excepts))); \
83} while (0)
84#define test2(func, y, x, result, excepts) \
85 test2_tol(func, (y), (x), (result), 0, (excepts))
86
87#define testall2_tol(prefix, y, x, result, tol, excepts) do { \
88 test2_tol(prefix, (double)(y), (double)(x), (double)(result), \
89 (tol) * ldexp(1.0, 1 - DBL_MANT_DIG), (excepts)); \
90 test2_tol(prefix##f, (float)(y), (float)(x), (float)(result), \

--- 8 unchanged lines hidden (view full) ---

99pi = 3.14159265358979323846264338327950280e+00L,
100pio3 = 1.04719755119659774615421446109316766e+00L,
101c3pi = 9.42477796076937971538793014983850839e+00L,
102c5pi = 1.57079632679489661923132169163975140e+01L,
103c7pi = 2.19911485751285526692385036829565196e+01L,
104c5pio3 = 5.23598775598298873077107230546583851e+00L,
105sqrt2m1 = 4.14213562373095048801688724209698081e-01L;
106
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
107/*
108 * Determine whether x and y are equal to within a relative error of tol,
109 * with two special rules:
110 * +0.0 != -0.0
111 * NaN == NaN
112 */
113int
114fpequal(long double x, long double y, long double tol)
115{
116 fenv_t env;
117 int ret;
118
106
119 if (isnan(x) && isnan(y))
120 return (1);
121 if (!signbit(x) != !signbit(y))
122 return (0);
123 if (x == y)
124 return (1);
125 if (tol == 0)
126 return (0);
127
128 /* Hard case: need to check the tolerance. */
129 feholdexcept(&env);
130 ret = fabsl(x - y) <= fabsl(y * tol);
131 fesetenv(&env);
132 return (ret);
133}
134
135/*
136 * Test special case inputs in asin(), acos() and atan(): signed
137 * zeroes, infinities, and NaNs.
138 */
139static void
140test_special(void)
141{
142

--- 344 unchanged lines hidden ---
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 ---