Home | History | Annotate | Line # | Download | only in libm
t_sinh.c revision 1.4
      1 /* $NetBSD: t_sinh.c,v 1.4 2011/10/18 14:16:42 jruoho Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jukka Ruohonen.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 #include <sys/cdefs.h>
     32 __RCSID("$NetBSD: t_sinh.c,v 1.4 2011/10/18 14:16:42 jruoho Exp $");
     33 
     34 #include <atf-c.h>
     35 #include <math.h>
     36 #include <stdio.h>
     37 
     38 /*
     39  * sinh(3)
     40  */
     41 ATF_TC(sinh_def);
     42 ATF_TC_HEAD(sinh_def, tc)
     43 {
     44 	atf_tc_set_md_var(tc, "descr", "Test the definition of sinh(3)");
     45 }
     46 
     47 ATF_TC_BODY(sinh_def, tc)
     48 {
     49 #ifndef __vax__
     50 	const double x[] = { 0.005, 0.05, 0.0, 1.0, 10.0, 20.0 };
     51 	const double eps = 1.0e-4;
     52 	double y, z;
     53 	size_t i;
     54 
     55 	for (i = 0; i < __arraycount(x); i++) {
     56 
     57 		y = sinh(x[i]);
     58 		z = (exp(x[i]) - exp(-x[i])) / 2;
     59 
     60 		(void)fprintf(stderr,
     61 		    "sinh(%0.03f) = %f\n(exp(%0.03f) - "
     62 		    "exp(-%0.03f)) / 2 = %f\n", x[i], y, x[i], x[i], z);
     63 
     64 		if (fabs(y - z) > eps)
     65 			atf_tc_fail_nonfatal("sinh(%0.03f) != %0.03f\n",
     66 			    x[i], z);
     67 	}
     68 #endif
     69 }
     70 
     71 ATF_TC(sinh_nan);
     72 ATF_TC_HEAD(sinh_nan, tc)
     73 {
     74 	atf_tc_set_md_var(tc, "descr", "Test sinh(NaN) == NaN");
     75 }
     76 
     77 ATF_TC_BODY(sinh_nan, tc)
     78 {
     79 #ifndef __vax__
     80 	const double x = 0.0L / 0.0L;
     81 
     82 	ATF_CHECK(isnan(x) != 0);
     83 	ATF_CHECK(isnan(sinh(x)) != 0);
     84 #endif
     85 }
     86 
     87 ATF_TC(sinh_inf_neg);
     88 ATF_TC_HEAD(sinh_inf_neg, tc)
     89 {
     90 	atf_tc_set_md_var(tc, "descr", "Test sinh(-Inf) == -Inf");
     91 }
     92 
     93 ATF_TC_BODY(sinh_inf_neg, tc)
     94 {
     95 #ifndef __vax__
     96 	const double x = -1.0L / 0.0L;
     97 	double y = sinh(x);
     98 
     99 	ATF_CHECK(isinf(y) != 0);
    100 	ATF_CHECK(signbit(y) != 0);
    101 #endif
    102 }
    103 
    104 ATF_TC(sinh_inf_pos);
    105 ATF_TC_HEAD(sinh_inf_pos, tc)
    106 {
    107 	atf_tc_set_md_var(tc, "descr", "Test sinh(+Inf) == +Inf");
    108 }
    109 
    110 ATF_TC_BODY(sinh_inf_pos, tc)
    111 {
    112 #ifndef __vax__
    113 	const double x = 1.0L / 0.0L;
    114 	double y = sinh(x);
    115 
    116 	ATF_CHECK(isinf(y) != 0);
    117 	ATF_CHECK(signbit(y) == 0);
    118 #endif
    119 }
    120 
    121 ATF_TC(sinh_zero_neg);
    122 ATF_TC_HEAD(sinh_zero_neg, tc)
    123 {
    124 	atf_tc_set_md_var(tc, "descr", "Test sinh(-0.0) == -0.0");
    125 }
    126 
    127 ATF_TC_BODY(sinh_zero_neg, tc)
    128 {
    129 #ifndef __vax__
    130 	const double x = -0.0L;
    131 	double y = sinh(x);
    132 
    133 	if (fabs(y) > 0.0 || signbit(y) == 0)
    134 		atf_tc_fail_nonfatal("sinh(-0.0) != -0.0");
    135 #endif
    136 }
    137 
    138 ATF_TC(sinh_zero_pos);
    139 ATF_TC_HEAD(sinh_zero_pos, tc)
    140 {
    141 	atf_tc_set_md_var(tc, "descr", "Test sinh(+0.0) == +0.0");
    142 }
    143 
    144 ATF_TC_BODY(sinh_zero_pos, tc)
    145 {
    146 #ifndef __vax__
    147 	const double x = 0.0L;
    148 	double y = sinh(x);
    149 
    150 	if (fabs(y) > 0.0 || signbit(y) != 0)
    151 		atf_tc_fail_nonfatal("sinh(+0.0) != +0.0");
    152 #endif
    153 }
    154 
    155 /*
    156  * sinhf(3)
    157  */
    158 ATF_TC(sinhf_def);
    159 ATF_TC_HEAD(sinhf_def, tc)
    160 {
    161 	atf_tc_set_md_var(tc, "descr", "Test the definition of sinhf(3)");
    162 }
    163 
    164 ATF_TC_BODY(sinhf_def, tc)
    165 {
    166 #ifndef __vax__
    167 	const float x[] = { 0.005, 0.05, 0.0, 1.0, 10.0, 20.0 };
    168 	const float eps = 1.0e-2;
    169 	float y, z;
    170 	size_t i;
    171 
    172 	for (i = 0; i < __arraycount(x); i++) {
    173 
    174 		y = sinhf(x[i]);
    175 		z = (expf(x[i]) - expf(-x[i])) / 2;
    176 
    177 		(void)fprintf(stderr,
    178 		    "sinhf(%0.03f) = %f\n(expf(%0.03f) - "
    179 		    "expf(-%0.03f)) / 2 = %f\n", x[i], y, x[i], x[i], z);
    180 
    181 		if (fabsf(y - z) > eps)
    182 			atf_tc_fail_nonfatal("sinhf(%0.03f) != %0.03f\n",
    183 			    x[i], z);
    184 	}
    185 #endif
    186 }
    187 
    188 ATF_TC(sinhf_nan);
    189 ATF_TC_HEAD(sinhf_nan, tc)
    190 {
    191 	atf_tc_set_md_var(tc, "descr", "Test sinhf(NaN) == NaN");
    192 }
    193 
    194 ATF_TC_BODY(sinhf_nan, tc)
    195 {
    196 #ifndef __vax__
    197 	const float x = 0.0L / 0.0L;
    198 
    199 	ATF_CHECK(isnan(x) != 0);
    200 	ATF_CHECK(isnan(sinhf(x)) != 0);
    201 #endif
    202 }
    203 
    204 ATF_TC(sinhf_inf_neg);
    205 ATF_TC_HEAD(sinhf_inf_neg, tc)
    206 {
    207 	atf_tc_set_md_var(tc, "descr", "Test sinhf(-Inf) == -Inf");
    208 }
    209 
    210 ATF_TC_BODY(sinhf_inf_neg, tc)
    211 {
    212 #ifndef __vax__
    213 	const float x = -1.0L / 0.0L;
    214 	float y = sinhf(x);
    215 
    216 	ATF_CHECK(isinf(y) != 0);
    217 	ATF_CHECK(signbit(y) != 0);
    218 #endif
    219 }
    220 
    221 ATF_TC(sinhf_inf_pos);
    222 ATF_TC_HEAD(sinhf_inf_pos, tc)
    223 {
    224 	atf_tc_set_md_var(tc, "descr", "Test sinhf(+Inf) == +Inf");
    225 }
    226 
    227 ATF_TC_BODY(sinhf_inf_pos, tc)
    228 {
    229 #ifndef __vax__
    230 	const float x = 1.0L / 0.0L;
    231 	float y = sinhf(x);
    232 
    233 	ATF_CHECK(isinf(y) != 0);
    234 	ATF_CHECK(signbit(y) == 0);
    235 #endif
    236 }
    237 
    238 ATF_TC(sinhf_zero_neg);
    239 ATF_TC_HEAD(sinhf_zero_neg, tc)
    240 {
    241 	atf_tc_set_md_var(tc, "descr", "Test sinhf(-0.0) == -0.0");
    242 }
    243 
    244 ATF_TC_BODY(sinhf_zero_neg, tc)
    245 {
    246 #ifndef __vax__
    247 	const float x = -0.0L;
    248 	float y = sinhf(x);
    249 
    250 	if (fabsf(y) > 0.0 || signbit(y) == 0)
    251 		atf_tc_fail_nonfatal("sinhf(-0.0) != -0.0");
    252 #endif
    253 }
    254 
    255 ATF_TC(sinhf_zero_pos);
    256 ATF_TC_HEAD(sinhf_zero_pos, tc)
    257 {
    258 	atf_tc_set_md_var(tc, "descr", "Test sinhf(+0.0) == +0.0");
    259 }
    260 
    261 ATF_TC_BODY(sinhf_zero_pos, tc)
    262 {
    263 #ifndef __vax__
    264 	const float x = 0.0L;
    265 	float y = sinhf(x);
    266 
    267 	if (fabsf(y) > 0.0 || signbit(y) != 0)
    268 		atf_tc_fail_nonfatal("sinhf(+0.0) != +0.0");
    269 #endif
    270 }
    271 
    272 ATF_TP_ADD_TCS(tp)
    273 {
    274 
    275 	ATF_TP_ADD_TC(tp, sinh_def);
    276 	ATF_TP_ADD_TC(tp, sinh_nan);
    277 	ATF_TP_ADD_TC(tp, sinh_inf_neg);
    278 	ATF_TP_ADD_TC(tp, sinh_inf_pos);
    279 	ATF_TP_ADD_TC(tp, sinh_zero_neg);
    280 	ATF_TP_ADD_TC(tp, sinh_zero_pos);
    281 
    282 	ATF_TP_ADD_TC(tp, sinhf_def);
    283 	ATF_TP_ADD_TC(tp, sinhf_nan);
    284 	ATF_TP_ADD_TC(tp, sinhf_inf_neg);
    285 	ATF_TP_ADD_TC(tp, sinhf_inf_pos);
    286 	ATF_TP_ADD_TC(tp, sinhf_zero_neg);
    287 	ATF_TP_ADD_TC(tp, sinhf_zero_pos);
    288 
    289 	return atf_no_error();
    290 }
    291