1272343Sngie/* $NetBSD: t_sinh.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_sinh.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.23287470339, 1e4, }, 44272343Sngie { -2, -3.626860407847019, 1, }, 45272343Sngie { -1, -1.175201193643801, 1, }, 46272343Sngie { -0.05, -0.050020835937655, 1, }, 47272343Sngie { -0.001,-0.001000000166667, 1, }, 48272343Sngie { 0.001, 0.001000000166667, 1, }, 49272343Sngie { 0.05, 0.050020835937655, 1, }, 50272343Sngie { 1, 1.175201193643801, 1, }, 51272343Sngie { 2, 3.626860407847019, 1, }, 52272343Sngie { 10, 11013.23287470339, 1e4, }, 53272343Sngie}; 54272343Sngie 55272343Sngie/* 56272343Sngie * sinh(3) 57272343Sngie */ 58272343SngieATF_TC(sinh_inrange); 59272343SngieATF_TC_HEAD(sinh_inrange, tc) 60272343Sngie{ 61272343Sngie atf_tc_set_md_var(tc, "descr", "sinh(x) for some values"); 62272343Sngie} 63272343Sngie 64272343SngieATF_TC_BODY(sinh_inrange, tc) 65272343Sngie{ 66272343Sngie double eps; 67272343Sngie double x; 68272343Sngie double y; 69272343Sngie size_t i; 70272343Sngie 71272343Sngie for (i = 0; i < __arraycount(values); i++) { 72272343Sngie x = values[i].x; 73272343Sngie y = values[i].y; 74272343Sngie eps = 1e-15 * values[i].e; 75272343Sngie 76272343Sngie if (fabs(sinh(x) - y) > eps) 77272343Sngie atf_tc_fail_nonfatal("sinh(%g) != %g\n", x, y); 78272343Sngie } 79272343Sngie} 80272343Sngie 81272343SngieATF_TC(sinh_nan); 82272343SngieATF_TC_HEAD(sinh_nan, tc) 83272343Sngie{ 84272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinh(NaN) == NaN"); 85272343Sngie} 86272343Sngie 87272343SngieATF_TC_BODY(sinh_nan, tc) 88272343Sngie{ 89272343Sngie const double x = 0.0L / 0.0L; 90272343Sngie 91272343Sngie ATF_CHECK(isnan(x) != 0); 92272343Sngie ATF_CHECK(isnan(sinh(x)) != 0); 93272343Sngie} 94272343Sngie 95272343SngieATF_TC(sinh_inf_neg); 96272343SngieATF_TC_HEAD(sinh_inf_neg, tc) 97272343Sngie{ 98272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinh(-Inf) == -Inf"); 99272343Sngie} 100272343Sngie 101272343SngieATF_TC_BODY(sinh_inf_neg, tc) 102272343Sngie{ 103272343Sngie const double x = -1.0L / 0.0L; 104272343Sngie double y = sinh(x); 105272343Sngie 106272343Sngie ATF_CHECK(isinf(y) != 0); 107272343Sngie ATF_CHECK(signbit(y) != 0); 108272343Sngie} 109272343Sngie 110272343SngieATF_TC(sinh_inf_pos); 111272343SngieATF_TC_HEAD(sinh_inf_pos, tc) 112272343Sngie{ 113272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinh(+Inf) == +Inf"); 114272343Sngie} 115272343Sngie 116272343SngieATF_TC_BODY(sinh_inf_pos, tc) 117272343Sngie{ 118272343Sngie const double x = 1.0L / 0.0L; 119272343Sngie double y = sinh(x); 120272343Sngie 121272343Sngie ATF_CHECK(isinf(y) != 0); 122272343Sngie ATF_CHECK(signbit(y) == 0); 123272343Sngie} 124272343Sngie 125272343SngieATF_TC(sinh_zero_neg); 126272343SngieATF_TC_HEAD(sinh_zero_neg, tc) 127272343Sngie{ 128272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinh(-0.0) == -0.0"); 129272343Sngie} 130272343Sngie 131272343SngieATF_TC_BODY(sinh_zero_neg, tc) 132272343Sngie{ 133272343Sngie const double x = -0.0L; 134272343Sngie double y = sinh(x); 135272343Sngie 136272343Sngie if (fabs(y) > 0.0 || signbit(y) == 0) 137272343Sngie atf_tc_fail_nonfatal("sinh(-0.0) != -0.0"); 138272343Sngie} 139272343Sngie 140272343SngieATF_TC(sinh_zero_pos); 141272343SngieATF_TC_HEAD(sinh_zero_pos, tc) 142272343Sngie{ 143272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinh(+0.0) == +0.0"); 144272343Sngie} 145272343Sngie 146272343SngieATF_TC_BODY(sinh_zero_pos, tc) 147272343Sngie{ 148272343Sngie const double x = 0.0L; 149272343Sngie double y = sinh(x); 150272343Sngie 151272343Sngie if (fabs(y) > 0.0 || signbit(y) != 0) 152272343Sngie atf_tc_fail_nonfatal("sinh(+0.0) != +0.0"); 153272343Sngie} 154272343Sngie 155272343Sngie/* 156272343Sngie * sinhf(3) 157272343Sngie */ 158272343SngieATF_TC(sinhf_inrange); 159272343SngieATF_TC_HEAD(sinhf_inrange, tc) 160272343Sngie{ 161272343Sngie atf_tc_set_md_var(tc, "descr", "sinhf(x) for some values"); 162272343Sngie} 163272343Sngie 164272343SngieATF_TC_BODY(sinhf_inrange, tc) 165272343Sngie{ 166272343Sngie float eps; 167272343Sngie float x; 168272343Sngie float y; 169272343Sngie size_t i; 170272343Sngie 171272343Sngie for (i = 0; i < __arraycount(values); i++) { 172272343Sngie x = values[i].x; 173272343Sngie y = values[i].y; 174272343Sngie eps = 1e-6 * values[i].e; 175272343Sngie 176272343Sngie if (fabsf(sinhf(x) - y) > eps) 177272343Sngie atf_tc_fail_nonfatal("sinhf(%g) != %g\n", x, y); 178272343Sngie } 179272343Sngie} 180272343Sngie 181272343SngieATF_TC(sinhf_nan); 182272343SngieATF_TC_HEAD(sinhf_nan, tc) 183272343Sngie{ 184272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinhf(NaN) == NaN"); 185272343Sngie} 186272343Sngie 187272343SngieATF_TC_BODY(sinhf_nan, tc) 188272343Sngie{ 189272343Sngie const float x = 0.0L / 0.0L; 190272343Sngie 191272343Sngie ATF_CHECK(isnan(x) != 0); 192272343Sngie ATF_CHECK(isnan(sinhf(x)) != 0); 193272343Sngie} 194272343Sngie 195272343SngieATF_TC(sinhf_inf_neg); 196272343SngieATF_TC_HEAD(sinhf_inf_neg, tc) 197272343Sngie{ 198272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinhf(-Inf) == -Inf"); 199272343Sngie} 200272343Sngie 201272343SngieATF_TC_BODY(sinhf_inf_neg, tc) 202272343Sngie{ 203272343Sngie const float x = -1.0L / 0.0L; 204272343Sngie float y = sinhf(x); 205272343Sngie 206272343Sngie ATF_CHECK(isinf(y) != 0); 207272343Sngie ATF_CHECK(signbit(y) != 0); 208272343Sngie} 209272343Sngie 210272343SngieATF_TC(sinhf_inf_pos); 211272343SngieATF_TC_HEAD(sinhf_inf_pos, tc) 212272343Sngie{ 213272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinhf(+Inf) == +Inf"); 214272343Sngie} 215272343Sngie 216272343SngieATF_TC_BODY(sinhf_inf_pos, tc) 217272343Sngie{ 218272343Sngie const float x = 1.0L / 0.0L; 219272343Sngie float y = sinhf(x); 220272343Sngie 221272343Sngie ATF_CHECK(isinf(y) != 0); 222272343Sngie ATF_CHECK(signbit(y) == 0); 223272343Sngie} 224272343Sngie 225272343SngieATF_TC(sinhf_zero_neg); 226272343SngieATF_TC_HEAD(sinhf_zero_neg, tc) 227272343Sngie{ 228272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinhf(-0.0) == -0.0"); 229272343Sngie} 230272343Sngie 231272343SngieATF_TC_BODY(sinhf_zero_neg, tc) 232272343Sngie{ 233272343Sngie const float x = -0.0L; 234272343Sngie float y = sinhf(x); 235272343Sngie 236272343Sngie if (fabsf(y) > 0.0 || signbit(y) == 0) 237272343Sngie atf_tc_fail_nonfatal("sinhf(-0.0) != -0.0"); 238272343Sngie} 239272343Sngie 240272343SngieATF_TC(sinhf_zero_pos); 241272343SngieATF_TC_HEAD(sinhf_zero_pos, tc) 242272343Sngie{ 243272343Sngie atf_tc_set_md_var(tc, "descr", "Test sinhf(+0.0) == +0.0"); 244272343Sngie} 245272343Sngie 246272343SngieATF_TC_BODY(sinhf_zero_pos, tc) 247272343Sngie{ 248272343Sngie const float x = 0.0L; 249272343Sngie float y = sinhf(x); 250272343Sngie 251272343Sngie if (fabsf(y) > 0.0 || signbit(y) != 0) 252272343Sngie atf_tc_fail_nonfatal("sinhf(+0.0) != +0.0"); 253272343Sngie} 254272343Sngie 255272343SngieATF_TP_ADD_TCS(tp) 256272343Sngie{ 257272343Sngie 258272343Sngie ATF_TP_ADD_TC(tp, sinh_inrange); 259272343Sngie ATF_TP_ADD_TC(tp, sinh_nan); 260272343Sngie ATF_TP_ADD_TC(tp, sinh_inf_neg); 261272343Sngie ATF_TP_ADD_TC(tp, sinh_inf_pos); 262272343Sngie ATF_TP_ADD_TC(tp, sinh_zero_neg); 263272343Sngie ATF_TP_ADD_TC(tp, sinh_zero_pos); 264272343Sngie 265272343Sngie ATF_TP_ADD_TC(tp, sinhf_inrange); 266272343Sngie ATF_TP_ADD_TC(tp, sinhf_nan); 267272343Sngie ATF_TP_ADD_TC(tp, sinhf_inf_neg); 268272343Sngie ATF_TP_ADD_TC(tp, sinhf_inf_pos); 269272343Sngie ATF_TP_ADD_TC(tp, sinhf_zero_neg); 270272343Sngie ATF_TP_ADD_TC(tp, sinhf_zero_pos); 271272343Sngie 272272343Sngie return atf_no_error(); 273272343Sngie} 274