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