1272343Sngie/* $NetBSD: t_cosh.c,v 1.6 2014/03/03 10:39:08 martin Exp $ */ 2272343Sngie 3272343Sngie/*- 4272343Sngie * Copyright (c) 2011 The NetBSD Foundation, Inc. 5272343Sngie * All rights reserved. 6272343Sngie * 7272343Sngie * This code is derived from software contributed to The NetBSD Foundation 8272343Sngie * by Jukka Ruohonen. 9272343Sngie * 10272343Sngie * Redistribution and use in source and binary forms, with or without 11272343Sngie * modification, are permitted provided that the following conditions 12272343Sngie * are met: 13272343Sngie * 1. Redistributions of source code must retain the above copyright 14272343Sngie * notice, this list of conditions and the following disclaimer. 15272343Sngie * 2. Redistributions in binary form must reproduce the above copyright 16272343Sngie * notice, this list of conditions and the following disclaimer in the 17272343Sngie * documentation and/or other materials provided with the distribution. 18272343Sngie * 19272343Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20272343Sngie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21272343Sngie * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22272343Sngie * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23272343Sngie * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24272343Sngie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25272343Sngie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26272343Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27272343Sngie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28272343Sngie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29272343Sngie * POSSIBILITY OF SUCH DAMAGE. 30272343Sngie */ 31272343Sngie#include <sys/cdefs.h> 32272343Sngie__RCSID("$NetBSD: t_cosh.c,v 1.6 2014/03/03 10:39:08 martin Exp $"); 33272343Sngie 34272343Sngie#include <atf-c.h> 35272343Sngie#include <math.h> 36272343Sngie#include <stdio.h> 37272343Sngie 38272343Sngiestatic const struct { 39272343Sngie double x; 40272343Sngie double y; 41272343Sngie double e; 42272343Sngie} values[] = { 43272343Sngie { -10, 11013.23292010332, 1e4, }, 44272343Sngie { -2, 3.762195691083631, 1, }, 45272343Sngie { -1, 1.543080634815244, 1, }, 46272343Sngie { -0.05, 1.001250260438369, 1, }, 47272343Sngie { -0.001, 1.000000500000042, 1, }, 48272343Sngie { 0, 1, 1, }, 49272343Sngie { 0.001, 1.000000500000042, 1, }, 50272343Sngie { 0.05, 1.001250260438369, 1, }, 51272343Sngie { 1, 1.543080634815244, 1, }, 52272343Sngie { 2, 3.762195691083631, 1, }, 53272343Sngie { 10, 11013.23292010332, 1e4, }, 54272343Sngie}; 55272343Sngie 56272343Sngie/* 57272343Sngie * cosh(3) 58272343Sngie */ 59272343SngieATF_TC(cosh_inrange); 60272343SngieATF_TC_HEAD(cosh_inrange, tc) 61272343Sngie{ 62272343Sngie atf_tc_set_md_var(tc, "descr", "cosh(x) for some values"); 63272343Sngie} 64272343Sngie 65272343SngieATF_TC_BODY(cosh_inrange, tc) 66272343Sngie{ 67272343Sngie double eps; 68272343Sngie double x; 69272343Sngie double y; 70272343Sngie size_t i; 71272343Sngie 72272343Sngie for (i = 0; i < __arraycount(values); i++) { 73272343Sngie x = values[i].x; 74272343Sngie y = values[i].y; 75272343Sngie eps = 1e-15 * values[i].e; 76272343Sngie 77272343Sngie if (fabs(cosh(x) - y) > eps) 78272343Sngie atf_tc_fail_nonfatal("cosh(%g) != %g\n", x, y); 79272343Sngie } 80272343Sngie} 81272343Sngie 82272343SngieATF_TC(cosh_nan); 83272343SngieATF_TC_HEAD(cosh_nan, tc) 84272343Sngie{ 85272343Sngie atf_tc_set_md_var(tc, "descr", "Test cosh(NaN) == NaN"); 86272343Sngie} 87272343Sngie 88272343SngieATF_TC_BODY(cosh_nan, tc) 89272343Sngie{ 90272343Sngie const double x = 0.0L / 0.0L; 91272343Sngie 92272343Sngie ATF_CHECK(isnan(x) != 0); 93272343Sngie ATF_CHECK(isnan(cosh(x)) != 0); 94272343Sngie} 95272343Sngie 96272343SngieATF_TC(cosh_inf_neg); 97272343SngieATF_TC_HEAD(cosh_inf_neg, tc) 98272343Sngie{ 99272343Sngie atf_tc_set_md_var(tc, "descr", "Test cosh(-Inf) == +Inf"); 100272343Sngie} 101272343Sngie 102272343SngieATF_TC_BODY(cosh_inf_neg, tc) 103272343Sngie{ 104272343Sngie const double x = -1.0L / 0.0L; 105272343Sngie double y = cosh(x); 106272343Sngie 107272343Sngie ATF_CHECK(isinf(y) != 0); 108272343Sngie ATF_CHECK(signbit(y) == 0); 109272343Sngie} 110272343Sngie 111272343SngieATF_TC(cosh_inf_pos); 112272343SngieATF_TC_HEAD(cosh_inf_pos, tc) 113272343Sngie{ 114272343Sngie atf_tc_set_md_var(tc, "descr", "Test cosh(+Inf) == +Inf"); 115272343Sngie} 116272343Sngie 117272343SngieATF_TC_BODY(cosh_inf_pos, tc) 118272343Sngie{ 119272343Sngie const double x = 1.0L / 0.0L; 120272343Sngie double y = cosh(x); 121272343Sngie 122272343Sngie ATF_CHECK(isinf(y) != 0); 123272343Sngie ATF_CHECK(signbit(y) == 0); 124272343Sngie} 125272343Sngie 126272343SngieATF_TC(cosh_zero_neg); 127272343SngieATF_TC_HEAD(cosh_zero_neg, tc) 128272343Sngie{ 129272343Sngie atf_tc_set_md_var(tc, "descr", "Test cosh(-0.0) == 1.0"); 130272343Sngie} 131272343Sngie 132272343SngieATF_TC_BODY(cosh_zero_neg, tc) 133272343Sngie{ 134272343Sngie const double x = -0.0L; 135272343Sngie 136272343Sngie if (cosh(x) != 1.0) 137272343Sngie atf_tc_fail_nonfatal("cosh(-0.0) != 1.0"); 138272343Sngie} 139272343Sngie 140272343SngieATF_TC(cosh_zero_pos); 141272343SngieATF_TC_HEAD(cosh_zero_pos, tc) 142272343Sngie{ 143272343Sngie atf_tc_set_md_var(tc, "descr", "Test cosh(+0.0) == 1.0"); 144272343Sngie} 145272343Sngie 146272343SngieATF_TC_BODY(cosh_zero_pos, tc) 147272343Sngie{ 148272343Sngie const double x = 0.0L; 149272343Sngie 150272343Sngie if (cosh(x) != 1.0) 151272343Sngie atf_tc_fail_nonfatal("cosh(+0.0) != 1.0"); 152272343Sngie} 153272343Sngie 154272343Sngie/* 155272343Sngie * coshf(3) 156272343Sngie */ 157272343SngieATF_TC(coshf_inrange); 158272343SngieATF_TC_HEAD(coshf_inrange, tc) 159272343Sngie{ 160272343Sngie atf_tc_set_md_var(tc, "descr", "coshf(x) for some values"); 161272343Sngie} 162272343Sngie 163272343SngieATF_TC_BODY(coshf_inrange, tc) 164272343Sngie{ 165272343Sngie float eps; 166272343Sngie float x; 167272343Sngie float y; 168272343Sngie size_t i; 169272343Sngie 170272343Sngie for (i = 0; i < __arraycount(values); i++) { 171272343Sngie x = values[i].x; 172272343Sngie y = values[i].y; 173272343Sngie eps = 1e-6 * values[i].e; 174272343Sngie 175272343Sngie if (fabsf(coshf(x) - y) > eps) 176272343Sngie atf_tc_fail_nonfatal("coshf(%g) != %g\n", x, y); 177272343Sngie } 178272343Sngie} 179272343Sngie 180272343SngieATF_TC(coshf_nan); 181272343SngieATF_TC_HEAD(coshf_nan, tc) 182272343Sngie{ 183272343Sngie atf_tc_set_md_var(tc, "descr", "Test coshf(NaN) == NaN"); 184272343Sngie} 185272343Sngie 186272343SngieATF_TC_BODY(coshf_nan, tc) 187272343Sngie{ 188272343Sngie const float x = 0.0L / 0.0L; 189272343Sngie 190272343Sngie ATF_CHECK(isnan(x) != 0); 191272343Sngie ATF_CHECK(isnan(coshf(x)) != 0); 192272343Sngie} 193272343Sngie 194272343SngieATF_TC(coshf_inf_neg); 195272343SngieATF_TC_HEAD(coshf_inf_neg, tc) 196272343Sngie{ 197272343Sngie atf_tc_set_md_var(tc, "descr", "Test coshf(-Inf) == +Inf"); 198272343Sngie} 199272343Sngie 200272343SngieATF_TC_BODY(coshf_inf_neg, tc) 201272343Sngie{ 202272343Sngie const float x = -1.0L / 0.0L; 203272343Sngie float y = coshf(x); 204272343Sngie 205272343Sngie ATF_CHECK(isinf(y) != 0); 206272343Sngie ATF_CHECK(signbit(y) == 0); 207272343Sngie} 208272343Sngie 209272343SngieATF_TC(coshf_inf_pos); 210272343SngieATF_TC_HEAD(coshf_inf_pos, tc) 211272343Sngie{ 212272343Sngie atf_tc_set_md_var(tc, "descr", "Test coshf(+Inf) == +Inf"); 213272343Sngie} 214272343Sngie 215272343SngieATF_TC_BODY(coshf_inf_pos, tc) 216272343Sngie{ 217272343Sngie const float x = 1.0L / 0.0L; 218272343Sngie float y = coshf(x); 219272343Sngie 220272343Sngie ATF_CHECK(isinf(y) != 0); 221272343Sngie ATF_CHECK(signbit(y) == 0); 222272343Sngie} 223272343Sngie 224272343SngieATF_TC(coshf_zero_neg); 225272343SngieATF_TC_HEAD(coshf_zero_neg, tc) 226272343Sngie{ 227272343Sngie atf_tc_set_md_var(tc, "descr", "Test coshf(-0.0) == 1.0"); 228272343Sngie} 229272343Sngie 230272343SngieATF_TC_BODY(coshf_zero_neg, tc) 231272343Sngie{ 232272343Sngie const float x = -0.0L; 233272343Sngie 234272343Sngie if (coshf(x) != 1.0) 235272343Sngie atf_tc_fail_nonfatal("coshf(-0.0) != 1.0"); 236272343Sngie} 237272343Sngie 238272343SngieATF_TC(coshf_zero_pos); 239272343SngieATF_TC_HEAD(coshf_zero_pos, tc) 240272343Sngie{ 241272343Sngie atf_tc_set_md_var(tc, "descr", "Test coshf(+0.0) == 1.0"); 242272343Sngie} 243272343Sngie 244272343SngieATF_TC_BODY(coshf_zero_pos, tc) 245272343Sngie{ 246272343Sngie const float x = 0.0L; 247272343Sngie 248272343Sngie if (coshf(x) != 1.0) 249272343Sngie atf_tc_fail_nonfatal("coshf(+0.0) != 1.0"); 250272343Sngie} 251272343Sngie 252272343SngieATF_TP_ADD_TCS(tp) 253272343Sngie{ 254272343Sngie 255272343Sngie ATF_TP_ADD_TC(tp, cosh_inrange); 256272343Sngie ATF_TP_ADD_TC(tp, cosh_nan); 257272343Sngie ATF_TP_ADD_TC(tp, cosh_inf_neg); 258272343Sngie ATF_TP_ADD_TC(tp, cosh_inf_pos); 259272343Sngie ATF_TP_ADD_TC(tp, cosh_zero_neg); 260272343Sngie ATF_TP_ADD_TC(tp, cosh_zero_pos); 261272343Sngie 262272343Sngie ATF_TP_ADD_TC(tp, coshf_inrange); 263272343Sngie ATF_TP_ADD_TC(tp, coshf_nan); 264272343Sngie ATF_TP_ADD_TC(tp, coshf_inf_neg); 265272343Sngie ATF_TP_ADD_TC(tp, coshf_inf_pos); 266272343Sngie ATF_TP_ADD_TC(tp, coshf_zero_neg); 267272343Sngie ATF_TP_ADD_TC(tp, coshf_zero_pos); 268272343Sngie 269272343Sngie return atf_no_error(); 270272343Sngie} 271