1272343Sngie/* $NetBSD: t_tan.c,v 1.5 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 32272343Sngie#include <atf-c.h> 33272343Sngie#include <math.h> 34272343Sngie 35272343Sngiestatic const struct { 36272343Sngie int angle; 37272343Sngie double x; 38272343Sngie double y; 39272343Sngie} angles[] = { 40272343Sngie { -180, -3.141592653589793, 0.0000000000000000 }, 41272343Sngie { -135, -2.356194490192345, 1.0000000000000000 }, 42272343Sngie { -45, -0.785398163397448, -1.0000000000000000 }, 43272343Sngie { 0, 0.000000000000000, 0.0000000000000000 }, 44272343Sngie { 30, 0.523598775598299, 0.5773502691896258 }, 45272343Sngie { 45, 0.785398163397448, 1.0000000000000000 }, 46272343Sngie { 60, 1.047197551196598, 1.7320508075688773 }, 47272343Sngie { 120, 2.094395102393195, -1.7320508075688773 }, 48272343Sngie { 135, 2.356194490192345, -1.0000000000000000 }, 49272343Sngie { 150, 2.617993877991494, -0.5773502691896258 }, 50272343Sngie { 180, 3.141592653589793, 0.0000000000000000 }, 51272343Sngie { 360, 6.283185307179586, 0.0000000000000000 } 52272343Sngie}; 53272343Sngie 54272343Sngie/* 55272343Sngie * tan(3) 56272343Sngie */ 57272343SngieATF_TC(tan_angles); 58272343SngieATF_TC_HEAD(tan_angles, tc) 59272343Sngie{ 60272343Sngie atf_tc_set_md_var(tc, "descr", "Test some selected angles"); 61272343Sngie} 62272343Sngie 63272343SngieATF_TC_BODY(tan_angles, tc) 64272343Sngie{ 65272343Sngie const double eps = 1.0e-14; 66272343Sngie size_t i; 67272343Sngie 68272343Sngie for (i = 0; i < __arraycount(angles); i++) { 69272343Sngie 70272343Sngie if (fabs(tan(angles[i].x) - angles[i].y) > eps) 71272343Sngie atf_tc_fail_nonfatal("tan(%d deg) != %0.01f", 72272343Sngie angles[i].angle, angles[i].y); 73272343Sngie } 74272343Sngie} 75272343Sngie 76272343SngieATF_TC(tan_nan); 77272343SngieATF_TC_HEAD(tan_nan, tc) 78272343Sngie{ 79272343Sngie atf_tc_set_md_var(tc, "descr", "Test tan(NaN) == NaN"); 80272343Sngie} 81272343Sngie 82272343SngieATF_TC_BODY(tan_nan, tc) 83272343Sngie{ 84272343Sngie const double x = 0.0L / 0.0L; 85272343Sngie 86272343Sngie ATF_CHECK(isnan(x) != 0); 87272343Sngie ATF_CHECK(isnan(tan(x)) != 0); 88272343Sngie} 89272343Sngie 90272343SngieATF_TC(tan_inf_neg); 91272343SngieATF_TC_HEAD(tan_inf_neg, tc) 92272343Sngie{ 93272343Sngie atf_tc_set_md_var(tc, "descr", "Test tan(-Inf) == NaN"); 94272343Sngie} 95272343Sngie 96272343SngieATF_TC_BODY(tan_inf_neg, tc) 97272343Sngie{ 98272343Sngie const double x = -1.0L / 0.0L; 99272343Sngie 100272343Sngie ATF_CHECK(isnan(tan(x)) != 0); 101272343Sngie} 102272343Sngie 103272343SngieATF_TC(tan_inf_pos); 104272343SngieATF_TC_HEAD(tan_inf_pos, tc) 105272343Sngie{ 106272343Sngie atf_tc_set_md_var(tc, "descr", "Test tan(+Inf) == NaN"); 107272343Sngie} 108272343Sngie 109272343SngieATF_TC_BODY(tan_inf_pos, tc) 110272343Sngie{ 111272343Sngie const double x = 1.0L / 0.0L; 112272343Sngie 113272343Sngie ATF_CHECK(isnan(tan(x)) != 0); 114272343Sngie} 115272343Sngie 116272343Sngie 117272343SngieATF_TC(tan_zero_neg); 118272343SngieATF_TC_HEAD(tan_zero_neg, tc) 119272343Sngie{ 120272343Sngie atf_tc_set_md_var(tc, "descr", "Test tan(-0.0) == -0.0"); 121272343Sngie} 122272343Sngie 123272343SngieATF_TC_BODY(tan_zero_neg, tc) 124272343Sngie{ 125272343Sngie const double x = -0.0L; 126272343Sngie 127272343Sngie ATF_CHECK(tan(x) == x); 128272343Sngie} 129272343Sngie 130272343SngieATF_TC(tan_zero_pos); 131272343SngieATF_TC_HEAD(tan_zero_pos, tc) 132272343Sngie{ 133272343Sngie atf_tc_set_md_var(tc, "descr", "Test tan(+0.0) == +0.0"); 134272343Sngie} 135272343Sngie 136272343SngieATF_TC_BODY(tan_zero_pos, tc) 137272343Sngie{ 138272343Sngie const double x = 0.0L; 139272343Sngie 140272343Sngie ATF_CHECK(tan(x) == x); 141272343Sngie} 142272343Sngie 143272343Sngie/* 144272343Sngie * tanf(3) 145272343Sngie */ 146272343SngieATF_TC(tanf_angles); 147272343SngieATF_TC_HEAD(tanf_angles, tc) 148272343Sngie{ 149272343Sngie atf_tc_set_md_var(tc, "descr", "Test some selected angles"); 150272343Sngie} 151272343Sngie 152272343SngieATF_TC_BODY(tanf_angles, tc) 153272343Sngie{ 154272343Sngie const float eps = 1.0e-6; 155272343Sngie float x, y; 156272343Sngie size_t i; 157272343Sngie 158272343Sngie for (i = 0; i < __arraycount(angles); i++) { 159272343Sngie 160272343Sngie x = angles[i].x; 161272343Sngie y = angles[i].y; 162272343Sngie 163272343Sngie if (fabsf(tanf(x) - y) > eps) 164272343Sngie atf_tc_fail_nonfatal("tanf(%d deg) != %0.01f", 165272343Sngie angles[i].angle, angles[i].y); 166272343Sngie } 167272343Sngie} 168272343Sngie 169272343SngieATF_TC(tanf_nan); 170272343SngieATF_TC_HEAD(tanf_nan, tc) 171272343Sngie{ 172272343Sngie atf_tc_set_md_var(tc, "descr", "Test tanf(NaN) == NaN"); 173272343Sngie} 174272343Sngie 175272343SngieATF_TC_BODY(tanf_nan, tc) 176272343Sngie{ 177272343Sngie const float x = 0.0L / 0.0L; 178272343Sngie 179272343Sngie ATF_CHECK(isnan(x) != 0); 180272343Sngie ATF_CHECK(isnan(tanf(x)) != 0); 181272343Sngie} 182272343Sngie 183272343SngieATF_TC(tanf_inf_neg); 184272343SngieATF_TC_HEAD(tanf_inf_neg, tc) 185272343Sngie{ 186272343Sngie atf_tc_set_md_var(tc, "descr", "Test tanf(-Inf) == NaN"); 187272343Sngie} 188272343Sngie 189272343SngieATF_TC_BODY(tanf_inf_neg, tc) 190272343Sngie{ 191272343Sngie const float x = -1.0L / 0.0L; 192272343Sngie 193272343Sngie if (isnan(tanf(x)) == 0) { 194272343Sngie atf_tc_expect_fail("PR lib/45362"); 195272343Sngie atf_tc_fail("tanf(-Inf) != NaN"); 196272343Sngie } 197272343Sngie} 198272343Sngie 199272343SngieATF_TC(tanf_inf_pos); 200272343SngieATF_TC_HEAD(tanf_inf_pos, tc) 201272343Sngie{ 202272343Sngie atf_tc_set_md_var(tc, "descr", "Test tanf(+Inf) == NaN"); 203272343Sngie} 204272343Sngie 205272343SngieATF_TC_BODY(tanf_inf_pos, tc) 206272343Sngie{ 207272343Sngie const float x = 1.0L / 0.0L; 208272343Sngie 209272343Sngie if (isnan(tanf(x)) == 0) { 210272343Sngie atf_tc_expect_fail("PR lib/45362"); 211272343Sngie atf_tc_fail("tanf(+Inf) != NaN"); 212272343Sngie } 213272343Sngie} 214272343Sngie 215272343Sngie 216272343SngieATF_TC(tanf_zero_neg); 217272343SngieATF_TC_HEAD(tanf_zero_neg, tc) 218272343Sngie{ 219272343Sngie atf_tc_set_md_var(tc, "descr", "Test tanf(-0.0) == -0.0"); 220272343Sngie} 221272343Sngie 222272343SngieATF_TC_BODY(tanf_zero_neg, tc) 223272343Sngie{ 224272343Sngie const float x = -0.0L; 225272343Sngie 226272343Sngie ATF_CHECK(tanf(x) == x); 227272343Sngie} 228272343Sngie 229272343SngieATF_TC(tanf_zero_pos); 230272343SngieATF_TC_HEAD(tanf_zero_pos, tc) 231272343Sngie{ 232272343Sngie atf_tc_set_md_var(tc, "descr", "Test tanf(+0.0) == +0.0"); 233272343Sngie} 234272343Sngie 235272343SngieATF_TC_BODY(tanf_zero_pos, tc) 236272343Sngie{ 237272343Sngie const float x = 0.0L; 238272343Sngie 239272343Sngie ATF_CHECK(tanf(x) == x); 240272343Sngie} 241272343Sngie 242272343SngieATF_TP_ADD_TCS(tp) 243272343Sngie{ 244272343Sngie 245272343Sngie ATF_TP_ADD_TC(tp, tan_angles); 246272343Sngie ATF_TP_ADD_TC(tp, tan_nan); 247272343Sngie ATF_TP_ADD_TC(tp, tan_inf_neg); 248272343Sngie ATF_TP_ADD_TC(tp, tan_inf_pos); 249272343Sngie ATF_TP_ADD_TC(tp, tan_zero_neg); 250272343Sngie ATF_TP_ADD_TC(tp, tan_zero_pos); 251272343Sngie 252272343Sngie ATF_TP_ADD_TC(tp, tanf_angles); 253272343Sngie ATF_TP_ADD_TC(tp, tanf_nan); 254272343Sngie ATF_TP_ADD_TC(tp, tanf_inf_neg); 255272343Sngie ATF_TP_ADD_TC(tp, tanf_inf_pos); 256272343Sngie ATF_TP_ADD_TC(tp, tanf_zero_neg); 257272343Sngie ATF_TP_ADD_TC(tp, tanf_zero_pos); 258272343Sngie 259272343Sngie return atf_no_error(); 260272343Sngie} 261