1 /* $NetBSD: t_asin.c,v 1.2 2013/04/09 12:11:04 isaki 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 32 #include <atf-c.h> 33 #include <math.h> 34 35 static const struct { 36 double x; 37 double y; 38 } values[] = { 39 { -1.0, -M_PI / 2, }, 40 { -0.9, -1.119769514998634, }, 41 { -0.5, -M_PI / 6, }, 42 { -0.1, -0.1001674211615598, }, 43 { 0.1, 0.1001674211615598, }, 44 { 0.5, M_PI / 6, }, 45 { 0.9, 1.119769514998634, }, 46 { 1.0, M_PI / 2, }, 47 }; 48 49 /* 50 * asin(3) 51 */ 52 ATF_TC(asin_nan); 53 ATF_TC_HEAD(asin_nan, tc) 54 { 55 atf_tc_set_md_var(tc, "descr", "Test asin(NaN) == NaN"); 56 } 57 58 ATF_TC_BODY(asin_nan, tc) 59 { 60 #ifndef __vax__ 61 const double x = 0.0L / 0.0L; 62 63 if (isnan(asin(x)) == 0) 64 atf_tc_fail_nonfatal("asin(NaN) != NaN"); 65 #endif 66 } 67 68 ATF_TC(asin_inf_neg); 69 ATF_TC_HEAD(asin_inf_neg, tc) 70 { 71 atf_tc_set_md_var(tc, "descr", "Test asin(-Inf) == NaN"); 72 } 73 74 ATF_TC_BODY(asin_inf_neg, tc) 75 { 76 #ifndef __vax__ 77 const double x = -1.0L / 0.0L; 78 79 if (isnan(asin(x)) == 0) 80 atf_tc_fail_nonfatal("asin(-Inf) != NaN"); 81 #endif 82 } 83 84 ATF_TC(asin_inf_pos); 85 ATF_TC_HEAD(asin_inf_pos, tc) 86 { 87 atf_tc_set_md_var(tc, "descr", "Test asin(+Inf) == NaN"); 88 } 89 90 ATF_TC_BODY(asin_inf_pos, tc) 91 { 92 #ifndef __vax__ 93 const double x = 1.0L / 0.0L; 94 95 if (isnan(asin(x)) == 0) 96 atf_tc_fail_nonfatal("asin(+Inf) != NaN"); 97 #endif 98 } 99 100 ATF_TC(asin_range); 101 ATF_TC_HEAD(asin_range, tc) 102 { 103 atf_tc_set_md_var(tc, "descr", "Test asin(x) == NaN, x < -1, x > 1"); 104 } 105 106 ATF_TC_BODY(asin_range, tc) 107 { 108 #ifndef __vax__ 109 const double x[] = { -1.1, -1.000000001, 1.1, 1.000000001 }; 110 size_t i; 111 112 for (i = 0; i < __arraycount(x); i++) { 113 114 if (isnan(asin(x[i])) == 0) 115 atf_tc_fail_nonfatal("asin(%f) != NaN", x[i]); 116 } 117 #endif 118 } 119 120 ATF_TC(asin_inrange); 121 ATF_TC_HEAD(asin_inrange, tc) 122 { 123 atf_tc_set_md_var(tc, "descr", "Test asin(x) for some values"); 124 } 125 126 ATF_TC_BODY(asin_inrange, tc) 127 { 128 #ifndef __vax__ 129 const double eps = 1.0e-15; 130 double y; 131 size_t i; 132 133 for (i = 0; i < __arraycount(values); i++) { 134 y = asin(values[i].x); 135 if (fabs(y - values[i].y) > eps) 136 atf_tc_fail_nonfatal("asin(%g) != %g", 137 values[i].x, values[i].y); 138 } 139 #endif 140 } 141 142 ATF_TC(asin_zero_neg); 143 ATF_TC_HEAD(asin_zero_neg, tc) 144 { 145 atf_tc_set_md_var(tc, "descr", "Test asin(-0.0) == -0.0"); 146 } 147 148 ATF_TC_BODY(asin_zero_neg, tc) 149 { 150 #ifndef __vax__ 151 const double x = -0.0L; 152 double y = asin(x); 153 154 if (fabs(y) > 0.0 || signbit(y) == 0) 155 atf_tc_fail_nonfatal("asin(-0.0) != -0.0"); 156 #endif 157 } 158 159 ATF_TC(asin_zero_pos); 160 ATF_TC_HEAD(asin_zero_pos, tc) 161 { 162 atf_tc_set_md_var(tc, "descr", "Test asin(+0.0) == +0.0"); 163 } 164 165 ATF_TC_BODY(asin_zero_pos, tc) 166 { 167 #ifndef __vax__ 168 const double x = 0.0L; 169 double y = asin(x); 170 171 if (fabs(y) > 0.0 || signbit(y) != 0) 172 atf_tc_fail_nonfatal("asin(+0.0) != +0.0"); 173 #endif 174 } 175 176 /* 177 * asinf(3) 178 */ 179 ATF_TC(asinf_nan); 180 ATF_TC_HEAD(asinf_nan, tc) 181 { 182 atf_tc_set_md_var(tc, "descr", "Test asinf(NaN) == NaN"); 183 } 184 185 ATF_TC_BODY(asinf_nan, tc) 186 { 187 #ifndef __vax__ 188 const float x = 0.0L / 0.0L; 189 190 if (isnan(asinf(x)) == 0) 191 atf_tc_fail_nonfatal("asinf(NaN) != NaN"); 192 #endif 193 } 194 195 ATF_TC(asinf_inf_neg); 196 ATF_TC_HEAD(asinf_inf_neg, tc) 197 { 198 atf_tc_set_md_var(tc, "descr", "Test asinf(-Inf) == NaN"); 199 } 200 201 ATF_TC_BODY(asinf_inf_neg, tc) 202 { 203 #ifndef __vax__ 204 const float x = -1.0L / 0.0L; 205 206 if (isnan(asinf(x)) == 0) 207 atf_tc_fail_nonfatal("asinf(-Inf) != NaN"); 208 #endif 209 } 210 211 ATF_TC(asinf_inf_pos); 212 ATF_TC_HEAD(asinf_inf_pos, tc) 213 { 214 atf_tc_set_md_var(tc, "descr", "Test asinf(+Inf) == NaN"); 215 } 216 217 ATF_TC_BODY(asinf_inf_pos, tc) 218 { 219 #ifndef __vax__ 220 const float x = 1.0L / 0.0L; 221 222 if (isnan(asinf(x)) == 0) 223 atf_tc_fail_nonfatal("asinf(+Inf) != NaN"); 224 #endif 225 } 226 227 ATF_TC(asinf_range); 228 ATF_TC_HEAD(asinf_range, tc) 229 { 230 atf_tc_set_md_var(tc, "descr", "Test asinf(x) == NaN, x < -1, x > 1"); 231 } 232 233 ATF_TC_BODY(asinf_range, tc) 234 { 235 #ifndef __vax__ 236 const float x[] = { -1.1, -1.0000001, 1.1, 1.0000001 }; 237 size_t i; 238 239 for (i = 0; i < __arraycount(x); i++) { 240 241 if (isnan(asinf(x[i])) == 0) 242 atf_tc_fail_nonfatal("asinf(%f) != NaN", x[i]); 243 } 244 #endif 245 } 246 247 ATF_TC(asinf_inrange); 248 ATF_TC_HEAD(asinf_inrange, tc) 249 { 250 atf_tc_set_md_var(tc, "descr", "Test asinf(x) for some values"); 251 } 252 253 ATF_TC_BODY(asinf_inrange, tc) 254 { 255 #ifndef __vax__ 256 const float eps = 1.0e-6; 257 float x; 258 float y; 259 size_t i; 260 261 for (i = 0; i < __arraycount(values); i++) { 262 x = values[i].x; 263 y = values[i].y; 264 if (fabs(asinf(x) - y) > eps) 265 atf_tc_fail_nonfatal("asinf(%g) != %g", x, y); 266 } 267 #endif 268 } 269 270 ATF_TC(asinf_zero_neg); 271 ATF_TC_HEAD(asinf_zero_neg, tc) 272 { 273 atf_tc_set_md_var(tc, "descr", "Test asinf(-0.0) == -0.0"); 274 } 275 276 ATF_TC_BODY(asinf_zero_neg, tc) 277 { 278 #ifndef __vax__ 279 const float x = -0.0L; 280 float y = asinf(x); 281 282 if (fabsf(y) > 0.0 || signbit(y) == 0) 283 atf_tc_fail_nonfatal("asinf(-0.0) != -0.0"); 284 #endif 285 } 286 287 ATF_TC(asinf_zero_pos); 288 ATF_TC_HEAD(asinf_zero_pos, tc) 289 { 290 atf_tc_set_md_var(tc, "descr", "Test asinf(+0.0) == +0.0"); 291 } 292 293 ATF_TC_BODY(asinf_zero_pos, tc) 294 { 295 #ifndef __vax__ 296 const float x = 0.0L; 297 float y = asinf(x); 298 299 if (fabsf(y) > 0.0 || signbit(y) != 0) 300 atf_tc_fail_nonfatal("asinf(+0.0) != +0.0"); 301 #endif 302 } 303 304 ATF_TP_ADD_TCS(tp) 305 { 306 307 ATF_TP_ADD_TC(tp, asin_nan); 308 ATF_TP_ADD_TC(tp, asin_inf_neg); 309 ATF_TP_ADD_TC(tp, asin_inf_pos); 310 ATF_TP_ADD_TC(tp, asin_range); 311 ATF_TP_ADD_TC(tp, asin_inrange); 312 ATF_TP_ADD_TC(tp, asin_zero_neg); 313 ATF_TP_ADD_TC(tp, asin_zero_pos); 314 315 ATF_TP_ADD_TC(tp, asinf_nan); 316 ATF_TP_ADD_TC(tp, asinf_inf_neg); 317 ATF_TP_ADD_TC(tp, asinf_inf_pos); 318 ATF_TP_ADD_TC(tp, asinf_range); 319 ATF_TP_ADD_TC(tp, asinf_inrange); 320 ATF_TP_ADD_TC(tp, asinf_zero_neg); 321 ATF_TP_ADD_TC(tp, asinf_zero_pos); 322 323 return atf_no_error(); 324 } 325