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