xref: /freebsd/contrib/netbsd-tests/lib/libm/t_casinh.c (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /* $NetBSD: t_casinh.c,v 1.2 2016/09/20 17:19:28 christos Exp $ */
2 
3 /*
4  * Written by Maya Rashish
5  * Public domain.
6  *
7  * Testing special values of casinh
8  * Values from ISO/IEC 9899:201x G.6.2.2
9  */
10 
11 #include <atf-c.h>
12 #include <complex.h>
13 #include <math.h>
14 
15 #define RE(z) (((double *)(&z))[0])
16 #define IM(z) (((double *)(&z))[1])
17 
18 static const struct {
19 	double input_re;
20 	double input_im;
21 	double result_re;
22 	double result_im;
23 } values[] = {
24 	{ +0,		+0,		+0,		+0},
25 	{ +5.032E3,	+INFINITY,	+INFINITY,	+M_PI/2},
26 	{ +INFINITY,	+5.023E3,	+INFINITY,	+0},
27 	{ +INFINITY,	+INFINITY,	+INFINITY,	+M_PI/4},
28 #ifdef __HAVE_NANF
29 	{ +INFINITY,	+NAN,		+INFINITY,	+NAN},
30 	{ +5.032E3,	+NAN,		+NAN,		+NAN}, /* + FE_INVALID optionally raised */
31 	{ +NAN,		+0,		+NAN,		+0},
32 	{ +NAN,		-5.023E3,	+NAN,		+NAN}, /* + FE_INVALID optionally raised */
33 	{ +NAN,		+INFINITY,	+INFINITY,	+NAN}, /* sign of real part of result unspecified */
34 	{ +NAN,		+NAN,		+NAN,		+NAN},
35 #endif
36 };
37 
38 #ifdef __HAVE_NANF
39 #define both_nan(a,b) (isnan(a) && isnan(b))
40 #else
41 #define both_nan(a,b) 0
42 #endif
43 
44 #define crude_equality(a,b) ((a == b) || both_nan(a,b))
45 
46 #define ATF_COMPLEX_EQUAL(a,b) do { \
47 	complex double ci = casinh(a); \
48 	ATF_CHECK_MSG(crude_equality(creal(ci),creal(b)) && \
49 	    crude_equality(cimag(ci), cimag(b)), \
50 	    "for casinh([%g,%g]) = [%g,%g] != [%g,%g]", \
51 	    creal(a), cimag(a), creal(ci), cimag(ci), creal(b), cimag(b)); \
52 } while (0/*CONSTCOND*/)
53 
54 
55 ATF_TC(casinh);
56 ATF_TC_HEAD(casinh, tc)
57 {
58 	atf_tc_set_md_var(tc, "descr","Check casinh family - special values");
59 }
60 
61 ATF_TC_BODY(casinh, tc)
62 {
63 	complex double input;
64 	complex double result;
65 	unsigned int i;
66 	for (i = 0; i < __arraycount(values); i++) {
67 		RE(input) = values[i].input_re;
68 		IM(input) = values[i].input_im;
69 		RE(result) = values[i].result_re;
70 		IM(result) = values[i].result_im;
71 		ATF_COMPLEX_EQUAL(input, result);
72 	}
73 }
74 
75 ATF_TP_ADD_TCS(tp)
76 {
77 
78 	ATF_TP_ADD_TC(tp, casinh);
79 
80 	return atf_no_error();
81 }
82