1*57718be8SEnji Cooper /* $NetBSD: t_sin.c,v 1.4 2014/03/03 10:39:08 martin Exp $ */ 2*57718be8SEnji Cooper 3*57718be8SEnji Cooper /*- 4*57718be8SEnji Cooper * Copyright (c) 2011 The NetBSD Foundation, Inc. 5*57718be8SEnji Cooper * All rights reserved. 6*57718be8SEnji Cooper * 7*57718be8SEnji Cooper * This code is derived from software contributed to The NetBSD Foundation 8*57718be8SEnji Cooper * by Jukka Ruohonen. 9*57718be8SEnji Cooper * 10*57718be8SEnji Cooper * Redistribution and use in source and binary forms, with or without 11*57718be8SEnji Cooper * modification, are permitted provided that the following conditions 12*57718be8SEnji Cooper * are met: 13*57718be8SEnji Cooper * 1. Redistributions of source code must retain the above copyright 14*57718be8SEnji Cooper * notice, this list of conditions and the following disclaimer. 15*57718be8SEnji Cooper * 2. Redistributions in binary form must reproduce the above copyright 16*57718be8SEnji Cooper * notice, this list of conditions and the following disclaimer in the 17*57718be8SEnji Cooper * documentation and/or other materials provided with the distribution. 18*57718be8SEnji Cooper * 19*57718be8SEnji Cooper * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20*57718be8SEnji Cooper * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21*57718be8SEnji Cooper * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*57718be8SEnji Cooper * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23*57718be8SEnji Cooper * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*57718be8SEnji Cooper * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*57718be8SEnji Cooper * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*57718be8SEnji Cooper * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*57718be8SEnji Cooper * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*57718be8SEnji Cooper * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*57718be8SEnji Cooper * POSSIBILITY OF SUCH DAMAGE. 30*57718be8SEnji Cooper */ 31*57718be8SEnji Cooper 32*57718be8SEnji Cooper #include <atf-c.h> 33*57718be8SEnji Cooper #include <math.h> 34*57718be8SEnji Cooper 35*57718be8SEnji Cooper static const struct { 36*57718be8SEnji Cooper int angle; 37*57718be8SEnji Cooper double x; 38*57718be8SEnji Cooper double y; 39*57718be8SEnji Cooper } angles[] = { 40*57718be8SEnji Cooper { -180, -3.141592653589793, 0.0000000000000000 }, 41*57718be8SEnji Cooper { -135, -2.356194490192345, -0.7071067811865476 }, 42*57718be8SEnji Cooper { -90, -1.570796326794897, -1.0000000000000000 }, 43*57718be8SEnji Cooper { -45, -0.785398163397448, -0.7071067811865476 }, 44*57718be8SEnji Cooper { 0, 0.000000000000000, 0.0000000000000000 }, 45*57718be8SEnji Cooper { 30, 0.523598775598299, 0.5000000000000000 }, 46*57718be8SEnji Cooper { 45, 0.785398163397448, 0.7071067811865476 }, 47*57718be8SEnji Cooper { 60, 1.047197551196598, 0.8660254037844386 }, 48*57718be8SEnji Cooper { 90, 1.570796326794897, 1.0000000000000000 }, 49*57718be8SEnji Cooper { 120, 2.094395102393195, 0.8660254037844386 }, 50*57718be8SEnji Cooper { 135, 2.356194490192345, 0.7071067811865476 }, 51*57718be8SEnji Cooper { 150, 2.617993877991494, 0.5000000000000000 }, 52*57718be8SEnji Cooper { 180, 3.141592653589793, 0.0000000000000000 }, 53*57718be8SEnji Cooper { 270, 4.712388980384690, -1.0000000000000000 }, 54*57718be8SEnji Cooper { 360, 6.283185307179586, 0.0000000000000000 } 55*57718be8SEnji Cooper }; 56*57718be8SEnji Cooper 57*57718be8SEnji Cooper /* 58*57718be8SEnji Cooper * sin(3) 59*57718be8SEnji Cooper */ 60*57718be8SEnji Cooper ATF_TC(sin_angles); 61*57718be8SEnji Cooper ATF_TC_HEAD(sin_angles, tc) 62*57718be8SEnji Cooper { 63*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test some selected angles"); 64*57718be8SEnji Cooper } 65*57718be8SEnji Cooper 66*57718be8SEnji Cooper ATF_TC_BODY(sin_angles, tc) 67*57718be8SEnji Cooper { 68*57718be8SEnji Cooper const double eps = 1.0e-15; 69*57718be8SEnji Cooper size_t i; 70*57718be8SEnji Cooper 71*57718be8SEnji Cooper for (i = 0; i < __arraycount(angles); i++) { 72*57718be8SEnji Cooper 73*57718be8SEnji Cooper if (fabs(sin(angles[i].x) - angles[i].y) > eps) 74*57718be8SEnji Cooper atf_tc_fail_nonfatal("sin(%d deg) != %0.01f", 75*57718be8SEnji Cooper angles[i].angle, angles[i].y); 76*57718be8SEnji Cooper } 77*57718be8SEnji Cooper } 78*57718be8SEnji Cooper 79*57718be8SEnji Cooper ATF_TC(sin_nan); 80*57718be8SEnji Cooper ATF_TC_HEAD(sin_nan, tc) 81*57718be8SEnji Cooper { 82*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sin(NaN) == NaN"); 83*57718be8SEnji Cooper } 84*57718be8SEnji Cooper 85*57718be8SEnji Cooper ATF_TC_BODY(sin_nan, tc) 86*57718be8SEnji Cooper { 87*57718be8SEnji Cooper const double x = 0.0L / 0.0L; 88*57718be8SEnji Cooper 89*57718be8SEnji Cooper ATF_CHECK(isnan(x) != 0); 90*57718be8SEnji Cooper ATF_CHECK(isnan(sin(x)) != 0); 91*57718be8SEnji Cooper } 92*57718be8SEnji Cooper 93*57718be8SEnji Cooper ATF_TC(sin_inf_neg); 94*57718be8SEnji Cooper ATF_TC_HEAD(sin_inf_neg, tc) 95*57718be8SEnji Cooper { 96*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sin(-Inf) == NaN"); 97*57718be8SEnji Cooper } 98*57718be8SEnji Cooper 99*57718be8SEnji Cooper ATF_TC_BODY(sin_inf_neg, tc) 100*57718be8SEnji Cooper { 101*57718be8SEnji Cooper const double x = -1.0L / 0.0L; 102*57718be8SEnji Cooper 103*57718be8SEnji Cooper ATF_CHECK(isnan(sin(x)) != 0); 104*57718be8SEnji Cooper } 105*57718be8SEnji Cooper 106*57718be8SEnji Cooper ATF_TC(sin_inf_pos); 107*57718be8SEnji Cooper ATF_TC_HEAD(sin_inf_pos, tc) 108*57718be8SEnji Cooper { 109*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sin(+Inf) == NaN"); 110*57718be8SEnji Cooper } 111*57718be8SEnji Cooper 112*57718be8SEnji Cooper ATF_TC_BODY(sin_inf_pos, tc) 113*57718be8SEnji Cooper { 114*57718be8SEnji Cooper const double x = 1.0L / 0.0L; 115*57718be8SEnji Cooper 116*57718be8SEnji Cooper ATF_CHECK(isnan(sin(x)) != 0); 117*57718be8SEnji Cooper } 118*57718be8SEnji Cooper 119*57718be8SEnji Cooper 120*57718be8SEnji Cooper ATF_TC(sin_zero_neg); 121*57718be8SEnji Cooper ATF_TC_HEAD(sin_zero_neg, tc) 122*57718be8SEnji Cooper { 123*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sin(-0.0) == -0.0"); 124*57718be8SEnji Cooper } 125*57718be8SEnji Cooper 126*57718be8SEnji Cooper ATF_TC_BODY(sin_zero_neg, tc) 127*57718be8SEnji Cooper { 128*57718be8SEnji Cooper const double x = -0.0L; 129*57718be8SEnji Cooper 130*57718be8SEnji Cooper ATF_CHECK(sin(x) == x); 131*57718be8SEnji Cooper } 132*57718be8SEnji Cooper 133*57718be8SEnji Cooper ATF_TC(sin_zero_pos); 134*57718be8SEnji Cooper ATF_TC_HEAD(sin_zero_pos, tc) 135*57718be8SEnji Cooper { 136*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sin(+0.0) == +0.0"); 137*57718be8SEnji Cooper } 138*57718be8SEnji Cooper 139*57718be8SEnji Cooper ATF_TC_BODY(sin_zero_pos, tc) 140*57718be8SEnji Cooper { 141*57718be8SEnji Cooper const double x = 0.0L; 142*57718be8SEnji Cooper 143*57718be8SEnji Cooper ATF_CHECK(sin(x) == x); 144*57718be8SEnji Cooper } 145*57718be8SEnji Cooper 146*57718be8SEnji Cooper /* 147*57718be8SEnji Cooper * sinf(3) 148*57718be8SEnji Cooper */ 149*57718be8SEnji Cooper ATF_TC(sinf_angles); 150*57718be8SEnji Cooper ATF_TC_HEAD(sinf_angles, tc) 151*57718be8SEnji Cooper { 152*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test some selected angles"); 153*57718be8SEnji Cooper } 154*57718be8SEnji Cooper 155*57718be8SEnji Cooper ATF_TC_BODY(sinf_angles, tc) 156*57718be8SEnji Cooper { 157*57718be8SEnji Cooper const float eps = 1.0e-6; 158*57718be8SEnji Cooper float x, y; 159*57718be8SEnji Cooper size_t i; 160*57718be8SEnji Cooper 161*57718be8SEnji Cooper for (i = 0; i < __arraycount(angles); i++) { 162*57718be8SEnji Cooper 163*57718be8SEnji Cooper x = angles[i].x; 164*57718be8SEnji Cooper y = angles[i].y; 165*57718be8SEnji Cooper 166*57718be8SEnji Cooper if (fabsf(sinf(x) - y) > eps) 167*57718be8SEnji Cooper atf_tc_fail_nonfatal("sinf(%d deg) != %0.01f", 168*57718be8SEnji Cooper angles[i].angle, angles[i].y); 169*57718be8SEnji Cooper } 170*57718be8SEnji Cooper } 171*57718be8SEnji Cooper 172*57718be8SEnji Cooper ATF_TC(sinf_nan); 173*57718be8SEnji Cooper ATF_TC_HEAD(sinf_nan, tc) 174*57718be8SEnji Cooper { 175*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sinf(NaN) == NaN"); 176*57718be8SEnji Cooper } 177*57718be8SEnji Cooper 178*57718be8SEnji Cooper ATF_TC_BODY(sinf_nan, tc) 179*57718be8SEnji Cooper { 180*57718be8SEnji Cooper const float x = 0.0L / 0.0L; 181*57718be8SEnji Cooper 182*57718be8SEnji Cooper ATF_CHECK(isnan(x) != 0); 183*57718be8SEnji Cooper ATF_CHECK(isnan(sinf(x)) != 0); 184*57718be8SEnji Cooper } 185*57718be8SEnji Cooper 186*57718be8SEnji Cooper ATF_TC(sinf_inf_neg); 187*57718be8SEnji Cooper ATF_TC_HEAD(sinf_inf_neg, tc) 188*57718be8SEnji Cooper { 189*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sinf(-Inf) == NaN"); 190*57718be8SEnji Cooper } 191*57718be8SEnji Cooper 192*57718be8SEnji Cooper ATF_TC_BODY(sinf_inf_neg, tc) 193*57718be8SEnji Cooper { 194*57718be8SEnji Cooper const float x = -1.0L / 0.0L; 195*57718be8SEnji Cooper 196*57718be8SEnji Cooper if (isnan(sinf(x)) == 0) { 197*57718be8SEnji Cooper atf_tc_expect_fail("PR lib/45362"); 198*57718be8SEnji Cooper atf_tc_fail("sinf(-Inf) != NaN"); 199*57718be8SEnji Cooper } 200*57718be8SEnji Cooper } 201*57718be8SEnji Cooper 202*57718be8SEnji Cooper ATF_TC(sinf_inf_pos); 203*57718be8SEnji Cooper ATF_TC_HEAD(sinf_inf_pos, tc) 204*57718be8SEnji Cooper { 205*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sinf(+Inf) == NaN"); 206*57718be8SEnji Cooper } 207*57718be8SEnji Cooper 208*57718be8SEnji Cooper ATF_TC_BODY(sinf_inf_pos, tc) 209*57718be8SEnji Cooper { 210*57718be8SEnji Cooper const float x = 1.0L / 0.0L; 211*57718be8SEnji Cooper 212*57718be8SEnji Cooper if (isnan(sinf(x)) == 0) { 213*57718be8SEnji Cooper atf_tc_expect_fail("PR lib/45362"); 214*57718be8SEnji Cooper atf_tc_fail("sinf(+Inf) != NaN"); 215*57718be8SEnji Cooper } 216*57718be8SEnji Cooper } 217*57718be8SEnji Cooper 218*57718be8SEnji Cooper 219*57718be8SEnji Cooper ATF_TC(sinf_zero_neg); 220*57718be8SEnji Cooper ATF_TC_HEAD(sinf_zero_neg, tc) 221*57718be8SEnji Cooper { 222*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sinf(-0.0) == -0.0"); 223*57718be8SEnji Cooper } 224*57718be8SEnji Cooper 225*57718be8SEnji Cooper ATF_TC_BODY(sinf_zero_neg, tc) 226*57718be8SEnji Cooper { 227*57718be8SEnji Cooper const float x = -0.0L; 228*57718be8SEnji Cooper 229*57718be8SEnji Cooper ATF_CHECK(sinf(x) == x); 230*57718be8SEnji Cooper } 231*57718be8SEnji Cooper 232*57718be8SEnji Cooper ATF_TC(sinf_zero_pos); 233*57718be8SEnji Cooper ATF_TC_HEAD(sinf_zero_pos, tc) 234*57718be8SEnji Cooper { 235*57718be8SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test sinf(+0.0) == +0.0"); 236*57718be8SEnji Cooper } 237*57718be8SEnji Cooper 238*57718be8SEnji Cooper ATF_TC_BODY(sinf_zero_pos, tc) 239*57718be8SEnji Cooper { 240*57718be8SEnji Cooper const float x = 0.0L; 241*57718be8SEnji Cooper 242*57718be8SEnji Cooper ATF_CHECK(sinf(x) == x); 243*57718be8SEnji Cooper } 244*57718be8SEnji Cooper 245*57718be8SEnji Cooper ATF_TP_ADD_TCS(tp) 246*57718be8SEnji Cooper { 247*57718be8SEnji Cooper 248*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sin_angles); 249*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sin_nan); 250*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sin_inf_neg); 251*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sin_inf_pos); 252*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sin_zero_neg); 253*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sin_zero_pos); 254*57718be8SEnji Cooper 255*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sinf_angles); 256*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sinf_nan); 257*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sinf_inf_neg); 258*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sinf_inf_pos); 259*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sinf_zero_neg); 260*57718be8SEnji Cooper ATF_TP_ADD_TC(tp, sinf_zero_pos); 261*57718be8SEnji Cooper 262*57718be8SEnji Cooper return atf_no_error(); 263*57718be8SEnji Cooper } 264