1 /* $OpenBSD: ctrig_test.c,v 1.1 2021/10/22 18:00:22 mbuhl Exp $ */ 2 /*- 3 * Copyright (c) 2008-2011 David Schultz <das@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #include "macros.h" 29 30 /* 31 * Tests for csin[h](), ccos[h](), and ctan[h](). 32 */ 33 34 #include <sys/cdefs.h> 35 __FBSDID("$FreeBSD$"); 36 37 #include <sys/param.h> 38 #include <complex.h> 39 #include <fenv.h> 40 #include <float.h> 41 #include <math.h> 42 #include <stdio.h> 43 44 #include "test-utils.h" 45 46 #pragma STDC FENV_ACCESS ON 47 #pragma STDC CX_LIMITED_RANGE OFF 48 49 /* 50 * Test that a function returns the correct value and sets the 51 * exception flags correctly. The exceptmask specifies which 52 * exceptions we should check. We need to be lenient for several 53 * reasons, but mainly because on some architectures it's impossible 54 * to raise FE_OVERFLOW without raising FE_INEXACT. 55 * 56 * These are macros instead of functions so that assert provides more 57 * meaningful error messages. 58 * 59 * XXX The volatile here is to avoid gcc's bogus constant folding and work 60 * around the lack of support for the FENV_ACCESS pragma. 61 */ 62 #define test_p(func, z, result, exceptmask, excepts, checksign) \ 63 do { \ 64 volatile long double complex _d = z; \ 65 debug(" testing %s(%Lg + %Lg I) == %Lg + %Lg I\n", #func, \ 66 creall(_d), cimagl(_d), creall(result), cimagl(result)); \ 67 ATF_CHECK(feclearexcept(FE_ALL_EXCEPT) == 0); \ 68 CHECK_CFPEQUAL_CS((func)(_d), (result), (checksign)); \ 69 volatile int _e = fetestexcept(exceptmask); \ 70 ATF_CHECK_MSG(_e == (excepts), \ 71 "%s fetestexcept(%s) (%#x) != %#x", __XSTRING(func), \ 72 __XSTRING(exceptmask), _e, (excepts)); \ 73 } while (0) 74 75 /* 76 * Test within a given tolerance. The tolerance indicates relative error 77 * in ulps. If result is 0, however, it measures absolute error in units 78 * of <format>_EPSILON. 79 */ 80 #define test_p_tol(func, z, result, tol) do { \ 81 debug(" testing %s(%Lg + %Lg I) ~= %Lg + %Lg I\n", #func, \ 82 creall(z), cimagl(z), creall(result), cimagl(result)); \ 83 CHECK_CFPEQUAL_TOL((func)(z), (result), (tol), FPE_ABS_ZERO); \ 84 } while (0) 85 86 /* These wrappers apply the identities f(conj(z)) = conj(f(z)). */ 87 #define test(func, z, result, exceptmask, excepts, checksign) do { \ 88 test_p(func, z, result, exceptmask, excepts, checksign); \ 89 test_p(func, conjl(z), conjl(result), exceptmask, excepts, checksign); \ 90 } while (0) 91 #define test_tol(func, z, result, tol) do { \ 92 test_p_tol(func, z, result, tol); \ 93 test_p_tol(func, conjl(z), conjl(result), tol); \ 94 } while (0) 95 #define test_odd_tol(func, z, result, tol) do { \ 96 test_tol(func, z, result, tol); \ 97 test_tol(func, -(z), -(result), tol); \ 98 } while (0) 99 #define test_even_tol(func, z, result, tol) do { \ 100 test_tol(func, z, result, tol); \ 101 test_tol(func, -(z), result, tol); \ 102 } while (0) 103 104 /* Test the given function in all precisions. */ 105 #define testall(func, x, result, exceptmask, excepts, checksign) do { \ 106 test(func, x, result, exceptmask, excepts, checksign); \ 107 test(func##f, x, result, exceptmask, excepts, checksign); \ 108 } while (0) 109 #define testall_odd(func, x, result, exceptmask, excepts, checksign) do { \ 110 testall(func, x, result, exceptmask, excepts, checksign); \ 111 testall(func, -x, -result, exceptmask, excepts, checksign); \ 112 } while (0) 113 #define testall_even(func, x, result, exceptmask, excepts, checksign) do { \ 114 testall(func, x, result, exceptmask, excepts, checksign); \ 115 testall(func, -x, result, exceptmask, excepts, checksign); \ 116 } while (0) 117 118 /* 119 * Test the given function in all precisions, within a given tolerance. 120 * The tolerance is specified in ulps. 121 */ 122 #define testall_tol(func, x, result, tol) do { \ 123 test_tol(func, x, result, tol * DBL_ULP()); \ 124 test_tol(func##f, x, result, tol * FLT_ULP()); \ 125 } while (0) 126 #define testall_odd_tol(func, x, result, tol) do { \ 127 test_odd_tol(func, x, result, tol * DBL_ULP()); \ 128 test_odd_tol(func##f, x, result, tol * FLT_ULP()); \ 129 } while (0) 130 #define testall_even_tol(func, x, result, tol) do { \ 131 test_even_tol(func, x, result, tol * DBL_ULP()); \ 132 test_even_tol(func##f, x, result, tol * FLT_ULP()); \ 133 } while (0) 134 135 136 ATF_TC(test_zero_input); 137 ATF_TC_HEAD(test_zero_input, tc) 138 { 139 atf_tc_set_md_var(tc, "descr", "test 0 input"); 140 } 141 ATF_TC_BODY(test_zero_input, tc) 142 { 143 long double complex zero = CMPLXL(0.0, 0.0); 144 145 /* csinh(0) = ctanh(0) = 0; ccosh(0) = 1 (no exceptions raised) */ 146 testall_odd(csinh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH); 147 testall_odd(csin, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH); 148 testall_even(ccosh, zero, 1.0, ALL_STD_EXCEPT, 0, CS_BOTH); 149 testall_even(ccos, zero, CMPLXL(1.0, -0.0), ALL_STD_EXCEPT, 0, CS_BOTH); 150 testall_odd(ctanh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH); 151 testall_odd(ctan, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH); 152 } 153 154 ATF_TC(test_nan_inputs); 155 ATF_TC_HEAD(test_nan_inputs, tc) 156 { 157 atf_tc_set_md_var(tc, "descr", "test NaN inputs"); 158 } 159 ATF_TC_BODY(test_nan_inputs, tc) 160 { 161 long double complex nan_nan = CMPLXL(NAN, NAN); 162 long double complex z; 163 164 /* 165 * IN CSINH CCOSH CTANH 166 * NaN,NaN NaN,NaN NaN,NaN NaN,NaN 167 * finite,NaN NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval] 168 * NaN,finite NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval] 169 * NaN,Inf NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval] 170 * Inf,NaN +-Inf,NaN Inf,NaN 1,+-0 171 * 0,NaN +-0,NaN NaN,+-0 +-0,NaN 172 * NaN,0 NaN,0 NaN,+-0 NaN,+-0 173 */ 174 z = nan_nan; 175 testall_odd(csinh, z, nan_nan, ALL_STD_EXCEPT, 0, 0); 176 testall_even(ccosh, z, nan_nan, ALL_STD_EXCEPT, 0, 0); 177 testall_odd(ctanh, z, nan_nan, ALL_STD_EXCEPT, 0, 0); 178 testall_odd(csin, z, nan_nan, ALL_STD_EXCEPT, 0, 0); 179 testall_even(ccos, z, nan_nan, ALL_STD_EXCEPT, 0, 0); 180 testall_odd(ctan, z, nan_nan, ALL_STD_EXCEPT, 0, 0); 181 182 z = CMPLXL(42, NAN); 183 testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0); 184 testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0); 185 /* XXX We allow a spurious inexact exception here. */ 186 testall_odd(ctanh, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0); 187 testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0); 188 testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0); 189 testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0); 190 191 z = CMPLXL(NAN, 42); 192 testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0); 193 testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0); 194 testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0); 195 testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0); 196 testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0); 197 /* XXX We allow a spurious inexact exception here. */ 198 testall_odd(ctan, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0); 199 200 z = CMPLXL(NAN, INFINITY); 201 testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0); 202 testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0); 203 testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0); 204 testall_odd(csin, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0); 205 testall_even(ccos, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, 206 CS_IMAG); 207 testall_odd(ctan, z, CMPLXL(0, 1), ALL_STD_EXCEPT, 0, CS_IMAG); 208 209 z = CMPLXL(INFINITY, NAN); 210 testall_odd(csinh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, 0); 211 testall_even(ccosh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, 212 CS_REAL); 213 testall_odd(ctanh, z, CMPLXL(1, 0), ALL_STD_EXCEPT, 0, CS_REAL); 214 testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0); 215 testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0); 216 testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0); 217 218 z = CMPLXL(0, NAN); 219 testall_odd(csinh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL); 220 testall_even(ccosh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0); 221 testall_odd(ctanh, z, CMPLXL(0, NAN), OPT_INVALID, 0, CS_REAL); 222 testall_odd(csin, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL); 223 testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0); 224 testall_odd(ctan, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL); 225 226 z = CMPLXL(NAN, 0); 227 testall_odd(csinh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG); 228 testall_even(ccosh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0); 229 testall_odd(ctanh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG); 230 testall_odd(csin, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0); 231 testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0); 232 testall_odd(ctan, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG); 233 } 234 235 ATF_TC(test_inf_inputs); 236 ATF_TC_HEAD(test_inf_inputs, tc) 237 { 238 atf_tc_set_md_var(tc, "descr", "test infinity inputs"); 239 } 240 ATF_TC_BODY(test_inf_inputs, tc) 241 { 242 static const long double finites[] = { 243 0, M_PI / 4, 3 * M_PI / 4, 5 * M_PI / 4, 244 }; 245 long double complex z, c, s; 246 unsigned i; 247 248 /* 249 * IN CSINH CCOSH CTANH 250 * Inf,Inf +-Inf,NaN inval +-Inf,NaN inval 1,+-0 251 * Inf,finite Inf cis(finite) Inf cis(finite) 1,0 sin(2 finite) 252 * 0,Inf +-0,NaN inval NaN,+-0 inval +-0,NaN 253 * finite,Inf NaN,NaN inval NaN,NaN inval NaN,NaN inval 254 */ 255 z = CMPLXL(INFINITY, INFINITY); 256 testall_odd(csinh, z, CMPLXL(INFINITY, NAN), 257 ALL_STD_EXCEPT, FE_INVALID, 0); 258 testall_even(ccosh, z, CMPLXL(INFINITY, NAN), 259 ALL_STD_EXCEPT, FE_INVALID, 0); 260 testall_odd(ctanh, z, CMPLXL(1, 0), ALL_STD_EXCEPT, 0, CS_REAL); 261 testall_odd(csin, z, CMPLXL(NAN, INFINITY), 262 ALL_STD_EXCEPT, FE_INVALID, 0); 263 testall_even(ccos, z, CMPLXL(INFINITY, NAN), 264 ALL_STD_EXCEPT, FE_INVALID, 0); 265 testall_odd(ctan, z, CMPLXL(0, 1), ALL_STD_EXCEPT, 0, CS_REAL); 266 267 /* XXX We allow spurious inexact exceptions here (hard to avoid). */ 268 for (i = 0; i < nitems(finites); i++) { 269 z = CMPLXL(INFINITY, finites[i]); 270 c = INFINITY * cosl(finites[i]); 271 s = finites[i] == 0 ? finites[i] : INFINITY * sinl(finites[i]); 272 testall_odd(csinh, z, CMPLXL(c, s), OPT_INEXACT, 0, CS_BOTH); 273 testall_even(ccosh, z, CMPLXL(c, s), OPT_INEXACT, 0, CS_BOTH); 274 testall_odd(ctanh, z, CMPLXL(1, 0 * sin(finites[i] * 2)), 275 OPT_INEXACT, 0, CS_BOTH); 276 z = CMPLXL(finites[i], INFINITY); 277 testall_odd(csin, z, CMPLXL(s, c), OPT_INEXACT, 0, CS_BOTH); 278 testall_even(ccos, z, CMPLXL(c, -s), OPT_INEXACT, 0, CS_BOTH); 279 testall_odd(ctan, z, CMPLXL(0 * sin(finites[i] * 2), 1), 280 OPT_INEXACT, 0, CS_BOTH); 281 } 282 283 z = CMPLXL(0, INFINITY); 284 testall_odd(csinh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, FE_INVALID, 0); 285 testall_even(ccosh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0); 286 testall_odd(ctanh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, FE_INVALID, CS_REAL); 287 z = CMPLXL(INFINITY, 0); 288 testall_odd(csin, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0); 289 testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0); 290 testall_odd(ctan, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, CS_IMAG); 291 292 z = CMPLXL(42, INFINITY); 293 testall_odd(csinh, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0); 294 testall_even(ccosh, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0); 295 /* XXX We allow a spurious inexact exception here. */ 296 testall_odd(ctanh, z, CMPLXL(NAN, NAN), OPT_INEXACT, FE_INVALID, 0); 297 z = CMPLXL(INFINITY, 42); 298 testall_odd(csin, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0); 299 testall_even(ccos, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0); 300 /* XXX We allow a spurious inexact exception here. */ 301 testall_odd(ctan, z, CMPLXL(NAN, NAN), OPT_INEXACT, FE_INVALID, 0); 302 } 303 304 ATF_TC(test_axes); 305 ATF_TC_HEAD(test_axes, tc) 306 { 307 atf_tc_set_md_var(tc, "descr", "test along the real/imaginary axes"); 308 } 309 ATF_TC_BODY(test_axes, tc) 310 { 311 static const long double nums[] = { 312 M_PI / 4, M_PI / 2, 3 * M_PI / 4, 313 5 * M_PI / 4, 3 * M_PI / 2, 7 * M_PI / 4, 314 }; 315 long double complex z; 316 unsigned i; 317 318 for (i = 0; i < nitems(nums); i++) { 319 /* Real axis */ 320 z = CMPLXL(nums[i], 0.0); 321 test_odd_tol(csinh, z, CMPLXL(sinh(nums[i]), 0), DBL_ULP()); 322 test_even_tol(ccosh, z, CMPLXL(cosh(nums[i]), 0), DBL_ULP()); 323 test_odd_tol(ctanh, z, CMPLXL(tanh(nums[i]), 0), DBL_ULP()); 324 test_odd_tol(csin, z, CMPLXL(sin(nums[i]), 325 copysign(0, cos(nums[i]))), DBL_ULP()); 326 test_even_tol(ccos, z, CMPLXL(cos(nums[i]), 327 -copysign(0, sin(nums[i]))), DBL_ULP()); 328 test_odd_tol(ctan, z, CMPLXL(tan(nums[i]), 0), DBL_ULP()); 329 330 test_odd_tol(csinhf, z, CMPLXL(sinhf(nums[i]), 0), FLT_ULP()); 331 test_even_tol(ccoshf, z, CMPLXL(coshf(nums[i]), 0), FLT_ULP()); 332 printf("%a %a\n", creal(z), cimag(z)); 333 printf("%a %a\n", creal(ctanhf(z)), cimag(ctanhf(z))); 334 printf("%a\n", nextafterf(tanhf(nums[i]), INFINITY)); 335 test_odd_tol(ctanhf, z, CMPLXL(tanhf(nums[i]), 0), 336 1.3 * FLT_ULP()); 337 test_odd_tol(csinf, z, CMPLXL(sinf(nums[i]), 338 copysign(0, cosf(nums[i]))), FLT_ULP()); 339 test_even_tol(ccosf, z, CMPLXL(cosf(nums[i]), 340 -copysign(0, sinf(nums[i]))), 2 * FLT_ULP()); 341 test_odd_tol(ctanf, z, CMPLXL(tanf(nums[i]), 0), FLT_ULP()); 342 343 /* Imaginary axis */ 344 z = CMPLXL(0.0, nums[i]); 345 test_odd_tol(csinh, z, CMPLXL(copysign(0, cos(nums[i])), 346 sin(nums[i])), DBL_ULP()); 347 test_even_tol(ccosh, z, CMPLXL(cos(nums[i]), 348 copysign(0, sin(nums[i]))), DBL_ULP()); 349 test_odd_tol(ctanh, z, CMPLXL(0, tan(nums[i])), DBL_ULP()); 350 test_odd_tol(csin, z, CMPLXL(0, sinh(nums[i])), DBL_ULP()); 351 test_even_tol(ccos, z, CMPLXL(cosh(nums[i]), -0.0), DBL_ULP()); 352 test_odd_tol(ctan, z, CMPLXL(0, tanh(nums[i])), DBL_ULP()); 353 354 test_odd_tol(csinhf, z, CMPLXL(copysign(0, cosf(nums[i])), 355 sinf(nums[i])), FLT_ULP()); 356 test_even_tol(ccoshf, z, CMPLXL(cosf(nums[i]), 357 copysign(0, sinf(nums[i]))), FLT_ULP()); 358 test_odd_tol(ctanhf, z, CMPLXL(0, tanf(nums[i])), FLT_ULP()); 359 test_odd_tol(csinf, z, CMPLXL(0, sinhf(nums[i])), FLT_ULP()); 360 test_even_tol(ccosf, z, CMPLXL(coshf(nums[i]), -0.0), 361 FLT_ULP()); 362 test_odd_tol(ctanf, z, CMPLXL(0, tanhf(nums[i])), 363 1.3 * FLT_ULP()); 364 } 365 } 366 367 ATF_TC(test_small_inputs); 368 ATF_TC_HEAD(test_small_inputs, tc) 369 { 370 atf_tc_set_md_var(tc, "descr", "test underflow inputs"); 371 } 372 ATF_TC_BODY(test_small_inputs, tc) 373 { 374 /* 375 * z = 0.5 + i Pi/4 376 * sinh(z) = (sinh(0.5) + i cosh(0.5)) * sqrt(2)/2 377 * cosh(z) = (cosh(0.5) + i sinh(0.5)) * sqrt(2)/2 378 * tanh(z) = (2cosh(0.5)sinh(0.5) + i) / (2 cosh(0.5)**2 - 1) 379 * z = -0.5 + i Pi/2 380 * sinh(z) = cosh(0.5) 381 * cosh(z) = -i sinh(0.5) 382 * tanh(z) = -coth(0.5) 383 * z = 1.0 + i 3Pi/4 384 * sinh(z) = (-sinh(1) + i cosh(1)) * sqrt(2)/2 385 * cosh(z) = (-cosh(1) + i sinh(1)) * sqrt(2)/2 386 * tanh(z) = (2cosh(1)sinh(1) - i) / (2cosh(1)**2 - 1) 387 */ 388 static const struct { 389 long double a, b; 390 long double sinh_a, sinh_b; 391 long double cosh_a, cosh_b; 392 long double tanh_a, tanh_b; 393 } tests[] = { 394 { 0.5L, 395 0.78539816339744830961566084581987572L, 396 0.36847002415910435172083660522240710L, 397 0.79735196663945774996093142586179334L, 398 0.79735196663945774996093142586179334L, 399 0.36847002415910435172083660522240710L, 400 0.76159415595576488811945828260479359L, 401 0.64805427366388539957497735322615032L }, 402 { -0.5L, 403 1.57079632679489661923132169163975144L, 404 0.0L, 405 1.12762596520638078522622516140267201L, 406 0.0L, 407 -0.52109530549374736162242562641149156L, 408 -2.16395341373865284877000401021802312L, 409 0.0L }, 410 { 1.0L, 411 2.35619449019234492884698253745962716L, 412 -0.83099273328405698212637979852748608L, 413 1.09112278079550143030545602018565236L, 414 -1.09112278079550143030545602018565236L, 415 0.83099273328405698212637979852748609L, 416 0.96402758007581688394641372410092315L, 417 -0.26580222883407969212086273981988897L } 418 }; 419 long double complex z; 420 unsigned i; 421 422 for (i = 0; i < nitems(tests); i++) { 423 z = CMPLXL(tests[i].a, tests[i].b); 424 testall_odd_tol(csinh, z, 425 CMPLXL(tests[i].sinh_a, tests[i].sinh_b), 1.1); 426 testall_even_tol(ccosh, z, 427 CMPLXL(tests[i].cosh_a, tests[i].cosh_b), 1.1); 428 testall_odd_tol(ctanh, z, 429 CMPLXL(tests[i].tanh_a, tests[i].tanh_b), 1.4); 430 } 431 } 432 433 ATF_TC(test_large_inputs); 434 ATF_TC_HEAD(test_large_inputs, tc) 435 { 436 atf_tc_set_md_var(tc, "descr", 437 "Test inputs that might cause overflow in a sloppy implementation"); 438 } 439 ATF_TC_BODY(test_large_inputs, tc) 440 { 441 long double complex z; 442 443 /* tanh() uses a threshold around x=22, so check both sides. */ 444 z = CMPLXL(21, 0.78539816339744830961566084581987572L); 445 testall_odd_tol(ctanh, z, 446 CMPLXL(1.0, 1.14990445285871196133287617611468468e-18L), 1.2); 447 z++; 448 testall_odd_tol(ctanh, z, 449 CMPLXL(1.0, 1.55622644822675930314266334585597964e-19L), 1); 450 451 z = CMPLXL(355, 0.78539816339744830961566084581987572L); 452 test_odd_tol(ctanh, z, 453 CMPLXL(1.0, 8.95257245135025991216632140458264468e-309L), 454 DBL_ULP()); 455 z = CMPLXL(30, 0x1p1023L); 456 test_odd_tol(ctanh, z, 457 CMPLXL(1.0, -1.62994325413993477997492170229268382e-26L), 458 DBL_ULP()); 459 z = CMPLXL(1, 0x1p1023L); 460 test_odd_tol(ctanh, z, 461 CMPLXL(0.878606311888306869546254022621986509L, 462 -0.225462792499754505792678258169527424L), 463 DBL_ULP()); 464 465 z = CMPLXL(710.6, 0.78539816339744830961566084581987572L); 466 test_odd_tol(csinh, z, 467 CMPLXL(1.43917579766621073533185387499658944e308L, 468 1.43917579766621073533185387499658944e308L), DBL_ULP()); 469 test_even_tol(ccosh, z, 470 CMPLXL(1.43917579766621073533185387499658944e308L, 471 1.43917579766621073533185387499658944e308L), DBL_ULP()); 472 473 z = CMPLXL(1500, 0.78539816339744830961566084581987572L); 474 testall_odd(csinh, z, CMPLXL(INFINITY, INFINITY), OPT_INEXACT, 475 FE_OVERFLOW, CS_BOTH); 476 testall_even(ccosh, z, CMPLXL(INFINITY, INFINITY), OPT_INEXACT, 477 FE_OVERFLOW, CS_BOTH); 478 } 479 480 ATF_TP_ADD_TCS(tp) 481 { 482 483 ATF_TP_ADD_TC(tp, test_zero_input); 484 ATF_TP_ADD_TC(tp, test_nan_inputs); 485 ATF_TP_ADD_TC(tp, test_inf_inputs); 486 ATF_TP_ADD_TC(tp, test_axes); 487 ATF_TP_ADD_TC(tp, test_small_inputs); 488 ATF_TP_ADD_TC(tp, test_large_inputs); 489 490 return (atf_no_error()); 491 } 492