1 /* $OpenBSD: testvectl.c,v 1.5 2013/08/05 09:29:51 kettenis Exp $ */ 2 3 /* 4 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* Test vectors for math functions. 20 See C9X section F.9. 21 22 On some systems it may be necessary to modify the default exception 23 settings of the floating point arithmetic unit. */ 24 25 #include <float.h> 26 27 #if LDBL_MANT_DIG == 64 28 #include <stdio.h> 29 #include <string.h> 30 int __isfinitel (long double); 31 32 /* Some compilers will not accept these expressions. */ 33 34 #define ZINF 1 35 #define ZMINF 2 36 #define ZNANL 3 37 #define ZPIL 4 38 #define ZPIO2L 4 39 40 extern long double INFINITYL, NANL, NEGZEROL; 41 long double MINFL; 42 extern long double PIL, PIO2L, PIO4L, MACHEPL; 43 long double MPIL; 44 long double MPIO2L; 45 long double MPIO4L; 46 long double THPIO4L = 2.35619449019234492884698L; 47 long double MTHPIO4L = -2.35619449019234492884698L; 48 long double SQRT2L = 1.414213562373095048802E0L; 49 long double SQRTHL = 7.071067811865475244008E-1L; 50 long double ZEROL = 0.0L; 51 long double HALFL = 0.5L; 52 long double MHALFL = -0.5L; 53 long double ONEL = 1.0L; 54 long double MONEL = -1.0L; 55 long double TWOL = 2.0L; 56 long double MTWOL = -2.0L; 57 long double THREEL = 3.0L; 58 long double MTHREEL = -3.0L; 59 60 /* Functions of one variable. */ 61 long double logl (long double); 62 long double expl (long double); 63 long double atanl (long double); 64 long double sinl (long double); 65 long double cosl (long double); 66 long double tanl (long double); 67 long double acosl (long double); 68 long double asinl (long double); 69 long double acoshl (long double); 70 long double asinhl (long double); 71 long double atanhl (long double); 72 long double sinhl (long double); 73 long double coshl (long double); 74 long double tanhl (long double); 75 long double exp2l (long double); 76 long double expm1l (long double); 77 long double log10l (long double); 78 long double log1pl (long double); 79 long double log2l (long double); 80 long double fabsl (long double); 81 long double erfl (long double); 82 long double erfcl (long double); 83 long double tgammal (long double); 84 long double lgammal (long double); 85 long double floorl (long double); 86 long double ceill (long double); 87 long double cbrtl (long double); 88 89 struct oneargument 90 { 91 char *name; /* Name of the function. */ 92 long double (*func) (long double); 93 long double *arg1; 94 long double *answer; 95 int thresh; /* Error report threshold. */ 96 }; 97 98 #if 0 99 {"sinl", sinl, 32767.L, 1.8750655394138942394239E-1L, 0}, 100 {"cosl", cosl, 32767.L, 9.8226335176928229845654E-1L, 0}, 101 {"tanl", tanl, 32767.L, 1.9089234430221485740826E-1L, 0}, 102 {"sinl", sinl, 8388607.L, 9.9234509376961249835628E-1L, 0}, 103 {"cosl", cosl, 8388607.L, -1.2349580912475928183718E-1L, 0}, 104 {"tanl", tanl, 8388607.L, -8.0354556223613614748329E0L, 0}, 105 {"sinl", sinl, 2147483647.L, -7.2491655514455639054829E-1L, 0}, 106 {"cosl", cosl, 2147483647.L, -6.8883669187794383467976E-1L, 0}, 107 {"tanl", tanl, 2147483647.L, 1.0523779637351339136698E0L, 0}, 108 {"sinl", sinl, PIO4L, 7.0710678118654752440084E-1L, 0}, 109 {"cosl", cosl, PIO2L, -2.50827880633416613471e-20L, 0}, 110 #endif 111 112 static struct oneargument test1[] = 113 { 114 {"atanl", atanl, &ONEL, &PIO4L, 0}, 115 {"sinl", sinl, &PIO2L, &ONEL, 0}, 116 {"cosl", cosl, &PIO4L, &SQRTHL, 0}, 117 {"acosl", acosl, &NANL, &NANL, 0}, 118 {"acosl", acosl, &ONEL, &ZEROL, 0}, 119 {"acosl", acosl, &TWOL, &NANL, 0}, 120 {"acosl", acosl, &MTWOL, &NANL, 0}, 121 {"asinl", asinl, &NANL, &NANL, 0}, 122 {"asinl", asinl, &ZEROL, &ZEROL, 0}, 123 {"asinl", asinl, &NEGZEROL, &NEGZEROL, 0}, 124 {"asinl", asinl, &TWOL, &NANL, 0}, 125 {"asinl", asinl, &MTWOL, &NANL, 0}, 126 {"atanl", atanl, &NANL, &NANL, 0}, 127 {"atanl", atanl, &ZEROL, &ZEROL, 0}, 128 {"atanl", atanl, &NEGZEROL, &NEGZEROL, 0}, 129 {"atanl", atanl, &INFINITYL, &PIO2L, 0}, 130 {"atanl", atanl, &MINFL, &MPIO2L, 0}, 131 {"cosl", cosl, &NANL, &NANL, 0}, 132 {"cosl", cosl, &ZEROL, &ONEL, 0}, 133 {"cosl", cosl, &NEGZEROL, &ONEL, 0}, 134 {"cosl", cosl, &INFINITYL, &NANL, 0}, 135 {"cosl", cosl, &MINFL, &NANL, 0}, 136 {"sinl", sinl, &NANL, &NANL, 0}, 137 {"sinl", sinl, &NEGZEROL, &NEGZEROL, 0}, 138 {"sinl", sinl, &ZEROL, &ZEROL, 0}, 139 {"sinl", sinl, &INFINITYL, &NANL, 0}, 140 {"sinl", sinl, &MINFL, &NANL, 0}, 141 {"tanl", tanl, &NANL, &NANL, 0}, 142 {"tanl", tanl, &ZEROL, &ZEROL, 0}, 143 {"tanl", tanl, &NEGZEROL, &NEGZEROL, 0}, 144 {"tanl", tanl, &INFINITYL, &NANL, 0}, 145 {"tanl", tanl, &MINFL, &NANL, 0}, 146 {"acoshl", acoshl, &NANL, &NANL, 0}, 147 {"acoshl", acoshl, &ONEL, &ZEROL, 0}, 148 {"acoshl", acoshl, &INFINITYL, &INFINITYL, 0}, 149 {"acoshl", acoshl, &HALFL, &NANL, 0}, 150 {"acoshl", acoshl, &MONEL, &NANL, 0}, 151 {"asinhl", asinhl, &NANL, &NANL, 0}, 152 {"asinhl", asinhl, &ZEROL, &ZEROL, 0}, 153 {"asinhl", asinhl, &NEGZEROL, &NEGZEROL, 0}, 154 {"asinhl", asinhl, &INFINITYL, &INFINITYL, 0}, 155 {"asinhl", asinhl, &MINFL, &MINFL, 0}, 156 {"atanhl", atanhl, &NANL, &NANL, 0}, 157 {"atanhl", atanhl, &ZEROL, &ZEROL, 0}, 158 {"atanhl", atanhl, &NEGZEROL, &NEGZEROL, 0}, 159 {"atanhl", atanhl, &ONEL, &INFINITYL, 0}, 160 {"atanhl", atanhl, &MONEL, &MINFL, 0}, 161 {"atanhl", atanhl, &TWOL, &NANL, 0}, 162 {"atanhl", atanhl, &MTWOL, &NANL, 0}, 163 {"coshl", coshl, &NANL, &NANL, 0}, 164 {"coshl", coshl, &ZEROL, &ONEL, 0}, 165 {"coshl", coshl, &NEGZEROL, &ONEL, 0}, 166 {"coshl", coshl, &INFINITYL, &INFINITYL, 0}, 167 {"coshl", coshl, &MINFL, &INFINITYL, 0}, 168 {"sinhl", sinhl, &NANL, &NANL, 0}, 169 {"sinhl", sinhl, &ZEROL, &ZEROL, 0}, 170 {"sinhl", sinhl, &NEGZEROL, &NEGZEROL, 0}, 171 {"sinhl", sinhl, &INFINITYL, &INFINITYL, 0}, 172 {"sinhl", sinhl, &MINFL, &MINFL, 0}, 173 {"tanhl", tanhl, &NANL, &NANL, 0}, 174 {"tanhl", tanhl, &ZEROL, &ZEROL, 0}, 175 {"tanhl", tanhl, &NEGZEROL, &NEGZEROL, 0}, 176 {"tanhl", tanhl, &INFINITYL, &ONEL, 0}, 177 {"tanhl", tanhl, &MINFL, &MONEL, 0}, 178 {"expl", expl, &NANL, &NANL, 0}, 179 {"expl", expl, &ZEROL, &ONEL, 0}, 180 {"expl", expl, &NEGZEROL, &ONEL, 0}, 181 {"expl", expl, &INFINITYL, &INFINITYL, 0}, 182 {"expl", expl, &MINFL, &ZEROL, 0}, 183 {"exp2l", exp2l, &NANL, &NANL, 0}, 184 {"exp2l", exp2l, &ZEROL, &ONEL, 0}, 185 {"exp2l", exp2l, &NEGZEROL, &ONEL, 0}, 186 {"exp2l", exp2l, &INFINITYL, &INFINITYL, 0}, 187 {"exp2l", exp2l, &MINFL, &ZEROL, 0}, 188 {"expm1l", expm1l, &NANL, &NANL, 0}, 189 {"expm1l", expm1l, &ZEROL, &ZEROL, 0}, 190 {"expm1l", expm1l, &NEGZEROL, &NEGZEROL, 0}, 191 {"expm1l", expm1l, &INFINITYL, &INFINITYL, 0}, 192 {"expm1l", expm1l, &MINFL, &MONEL, 0}, 193 {"logl", logl, &NANL, &NANL, 0}, 194 {"logl", logl, &ZEROL, &MINFL, 0}, 195 {"logl", logl, &NEGZEROL, &MINFL, 0}, 196 {"logl", logl, &ONEL, &ZEROL, 0}, 197 {"logl", logl, &MONEL, &NANL, 0}, 198 {"logl", logl, &INFINITYL, &INFINITYL, 0}, 199 {"log10l", log10l, &NANL, &NANL, 0}, 200 {"log10l", log10l, &ZEROL, &MINFL, 0}, 201 {"log10l", log10l, &NEGZEROL, &MINFL, 0}, 202 {"log10l", log10l, &ONEL, &ZEROL, 0}, 203 {"log10l", log10l, &MONEL, &NANL, 0}, 204 {"log10l", log10l, &INFINITYL, &INFINITYL, 0}, 205 {"log1pl", log1pl, &NANL, &NANL, 0}, 206 {"log1pl", log1pl, &ZEROL, &ZEROL, 0}, 207 {"log1pl", log1pl, &NEGZEROL, &NEGZEROL, 0}, 208 {"log1pl", log1pl, &MONEL, &MINFL, 0}, 209 {"log1pl", log1pl, &MTWOL, &NANL, 0}, 210 {"log1pl", log1pl, &INFINITYL, &INFINITYL, 0}, 211 {"log2l", log2l, &NANL, &NANL, 0}, 212 {"log2l", log2l, &ZEROL, &MINFL, 0}, 213 {"log2l", log2l, &NEGZEROL, &MINFL, 0}, 214 {"log2l", log2l, &MONEL, &NANL, 0}, 215 {"log2l", log2l, &INFINITYL, &INFINITYL, 0}, 216 /* {"fabsl", fabsl, &NANL, &NANL, 0}, */ 217 {"fabsl", fabsl, &ONEL, &ONEL, 0}, 218 {"fabsl", fabsl, &MONEL, &ONEL, 0}, 219 {"fabsl", fabsl, &ZEROL, &ZEROL, 0}, 220 {"fabsl", fabsl, &NEGZEROL, &ZEROL, 0}, 221 {"fabsl", fabsl, &INFINITYL, &INFINITYL, 0}, 222 {"fabsl", fabsl, &MINFL, &INFINITYL, 0}, 223 {"cbrtl", cbrtl, &NANL, &NANL, 0}, 224 {"cbrtl", cbrtl, &ZEROL, &ZEROL, 0}, 225 {"cbrtl", cbrtl, &NEGZEROL, &NEGZEROL, 0}, 226 {"cbrtl", cbrtl, &INFINITYL, &INFINITYL, 0}, 227 {"cbrtl", cbrtl, &MINFL, &MINFL, 0}, 228 {"erfl", erfl, &NANL, &NANL, 0}, 229 {"erfl", erfl, &ZEROL, &ZEROL, 0}, 230 {"erfl", erfl, &NEGZEROL, &NEGZEROL, 0}, 231 {"erfl", erfl, &INFINITYL, &ONEL, 0}, 232 {"erfl", erfl, &MINFL, &MONEL, 0}, 233 {"erfcl", erfcl, &NANL, &NANL, 0}, 234 {"erfcl", erfcl, &INFINITYL, &ZEROL, 0}, 235 {"erfcl", erfcl, &MINFL, &TWOL, 0}, 236 {"tgammal", tgammal, &NANL, &NANL, 0}, 237 {"tgammal", tgammal, &INFINITYL, &INFINITYL, 0}, 238 {"tgammal", tgammal, &MONEL, &NANL, 0}, 239 {"tgammal", tgammal, &ZEROL, &INFINITYL, 0}, 240 {"tgammal", tgammal, &MINFL, &NANL, 0}, 241 {"lgammal", lgammal, &NANL, &NANL, 0}, 242 {"lgammal", lgammal, &INFINITYL, &INFINITYL, 0}, 243 {"lgammal", lgammal, &MONEL, &INFINITYL, 0}, 244 {"lgammal", lgammal, &ZEROL, &INFINITYL, 0}, 245 {"lgammal", lgammal, &MINFL, &INFINITYL, 0}, 246 {"ceill", ceill, &NANL, &NANL, 0}, 247 {"ceill", ceill, &ZEROL, &ZEROL, 0}, 248 {"ceill", ceill, &NEGZEROL, &NEGZEROL, 0}, 249 {"ceill", ceill, &INFINITYL, &INFINITYL, 0}, 250 {"ceill", ceill, &MINFL, &MINFL, 0}, 251 {"floorl", floorl, &NANL, &NANL, 0}, 252 {"floorl", floorl, &ZEROL, &ZEROL, 0}, 253 {"floorl", floorl, &NEGZEROL, &NEGZEROL, 0}, 254 {"floorl", floorl, &INFINITYL, &INFINITYL, 0}, 255 {"floorl", floorl, &MINFL, &MINFL, 0}, 256 {"null", NULL, &ZEROL, &ZEROL, 0}, 257 }; 258 259 /* Functions of two variables. */ 260 long double atan2l (long double, long double); 261 long double powl (long double, long double); 262 263 struct twoarguments 264 { 265 char *name; /* Name of the function. */ 266 long double (*func) (long double, long double); 267 long double *arg1; 268 long double *arg2; 269 long double *answer; 270 int thresh; 271 }; 272 273 static struct twoarguments test2[] = 274 { 275 {"atan2l", atan2l, &ZEROL, &ONEL, &ZEROL, 0}, 276 {"atan2l", atan2l, &NEGZEROL, &ONEL,&NEGZEROL, 0}, 277 {"atan2l", atan2l, &ZEROL, &ZEROL, &ZEROL, 0}, 278 {"atan2l", atan2l, &NEGZEROL, &ZEROL, &NEGZEROL, 0}, 279 {"atan2l", atan2l, &ZEROL, &MONEL, &PIL, 0}, 280 {"atan2l", atan2l, &NEGZEROL, &MONEL, &MPIL, 0}, 281 {"atan2l", atan2l, &ZEROL, &NEGZEROL, &PIL, 0}, 282 {"atan2l", atan2l, &NEGZEROL, &NEGZEROL, &MPIL, 0}, 283 {"atan2l", atan2l, &ONEL, &ZEROL, &PIO2L, 0}, 284 {"atan2l", atan2l, &ONEL, &NEGZEROL, &PIO2L, 0}, 285 {"atan2l", atan2l, &MONEL, &ZEROL, &MPIO2L, 0}, 286 {"atan2l", atan2l, &MONEL, &NEGZEROL, &MPIO2L, 0}, 287 {"atan2l", atan2l, &ONEL, &INFINITYL, &ZEROL, 0}, 288 {"atan2l", atan2l, &MONEL, &INFINITYL, &NEGZEROL, 0}, 289 {"atan2l", atan2l, &INFINITYL, &ONEL, &PIO2L, 0}, 290 {"atan2l", atan2l, &INFINITYL, &MONEL, &PIO2L, 0}, 291 {"atan2l", atan2l, &MINFL, &ONEL, &MPIO2L, 0}, 292 {"atan2l", atan2l, &MINFL, &MONEL, &MPIO2L, 0}, 293 {"atan2l", atan2l, &ONEL, &MINFL, &PIL, 0}, 294 {"atan2l", atan2l, &MONEL, &MINFL, &MPIL, 0}, 295 {"atan2l", atan2l, &INFINITYL, &INFINITYL, &PIO4L, 0}, 296 {"atan2l", atan2l, &MINFL, &INFINITYL, &MPIO4L, 0}, 297 {"atan2l", atan2l, &INFINITYL, &MINFL, &THPIO4L, 0}, 298 {"atan2l", atan2l, &MINFL, &MINFL, &MTHPIO4L, 0}, 299 {"atan2l", atan2l, &ONEL, &ONEL, &PIO4L, 0}, 300 {"atan2l", atan2l, &NANL, &ONEL, &NANL, 0}, 301 {"atan2l", atan2l, &ONEL, &NANL, &NANL, 0}, 302 {"atan2l", atan2l, &NANL, &NANL, &NANL, 0}, 303 {"powl", powl, &ONEL, &ZEROL, &ONEL, 0}, 304 {"powl", powl, &ONEL, &NEGZEROL, &ONEL, 0}, 305 {"powl", powl, &MONEL, &ZEROL, &ONEL, 0}, 306 {"powl", powl, &MONEL, &NEGZEROL, &ONEL, 0}, 307 {"powl", powl, &INFINITYL, &ZEROL, &ONEL, 0}, 308 {"powl", powl, &INFINITYL, &NEGZEROL, &ONEL, 0}, 309 {"powl", powl, &NANL, &ZEROL, &ONEL, 0}, 310 {"powl", powl, &NANL, &NEGZEROL, &ONEL, 0}, 311 {"powl", powl, &TWOL, &INFINITYL, &INFINITYL, 0}, 312 {"powl", powl, &MTWOL, &INFINITYL, &INFINITYL, 0}, 313 {"powl", powl, &HALFL, &INFINITYL, &ZEROL, 0}, 314 {"powl", powl, &MHALFL, &INFINITYL, &ZEROL, 0}, 315 {"powl", powl, &TWOL, &MINFL, &ZEROL, 0}, 316 {"powl", powl, &MTWOL, &MINFL, &ZEROL, 0}, 317 {"powl", powl, &HALFL, &MINFL, &INFINITYL, 0}, 318 {"powl", powl, &MHALFL, &MINFL, &INFINITYL, 0}, 319 {"powl", powl, &INFINITYL, &HALFL, &INFINITYL, 0}, 320 {"powl", powl, &INFINITYL, &TWOL, &INFINITYL, 0}, 321 {"powl", powl, &INFINITYL, &MHALFL, &ZEROL, 0}, 322 {"powl", powl, &INFINITYL, &MTWOL, &ZEROL, 0}, 323 {"powl", powl, &MINFL, &THREEL, &MINFL, 0}, 324 {"powl", powl, &MINFL, &TWOL, &INFINITYL, 0}, 325 {"powl", powl, &MINFL, &MTHREEL, &NEGZEROL, 0}, 326 {"powl", powl, &MINFL, &MTWOL, &ZEROL, 0}, 327 {"powl", powl, &NANL, &ONEL, &NANL, 0}, 328 {"powl", powl, &ONEL, &NANL, &ONEL, 0}, 329 {"powl", powl, &NANL, &NANL, &NANL, 0}, 330 {"powl", powl, &ONEL, &INFINITYL, &ONEL, 0}, 331 {"powl", powl, &MONEL, &INFINITYL, &ONEL, 0}, 332 {"powl", powl, &ONEL, &MINFL, &ONEL, 0}, 333 {"powl", powl, &MONEL, &MINFL, &ONEL, 0}, 334 {"powl", powl, &MTWOL, &HALFL, &NANL, 0}, 335 {"powl", powl, &ZEROL, &MTHREEL, &INFINITYL, 0}, 336 {"powl", powl, &NEGZEROL, &MTHREEL, &MINFL, 0}, 337 {"powl", powl, &ZEROL, &MHALFL, &INFINITYL, 0}, 338 {"powl", powl, &NEGZEROL, &MHALFL, &INFINITYL, 0}, 339 {"powl", powl, &ZEROL, &THREEL, &ZEROL, 0}, 340 {"powl", powl, &NEGZEROL, &THREEL, &NEGZEROL, 0}, 341 {"powl", powl, &ZEROL, &HALFL, &ZEROL, 0}, 342 {"powl", powl, &NEGZEROL, &HALFL, &ZEROL, 0}, 343 {"null", NULL, &ZEROL, &ZEROL, &ZEROL, 0}, 344 }; 345 346 /* Integer functions of one variable. */ 347 348 int __isnanl (long double); 349 int __signbitl (long double); 350 351 struct intans 352 { 353 char *name; /* Name of the function. */ 354 int (*func) (long double); 355 long double *arg1; 356 int ianswer; 357 }; 358 359 static struct intans test3[] = 360 { 361 {"isfinitel", __isfinitel, &ZEROL, 1}, 362 {"isfinitel", __isfinitel, &INFINITYL, 0}, 363 {"isfinitel", __isfinitel, &MINFL, 0}, 364 {"isnanl", __isnanl, &NANL, 1}, 365 {"isnanl", __isnanl, &INFINITYL, 0}, 366 {"isnanl", __isnanl, &ZEROL, 0}, 367 {"isnanl", __isnanl, &NEGZEROL, 0}, 368 {"signbitl", __signbitl, &NEGZEROL, 1}, 369 {"signbitl", __signbitl, &MONEL, 1}, 370 {"signbitl", __signbitl, &ZEROL, 0}, 371 {"signbitl", __signbitl, &ONEL, 0}, 372 {"signbitl", __signbitl, &MINFL, 1}, 373 {"signbitl", __signbitl, &INFINITYL, 0}, 374 {"null", NULL, &ZEROL, 0}, 375 }; 376 377 static volatile long double x1; 378 static volatile long double x2; 379 static volatile long double y; 380 static volatile long double answer; 381 382 int 383 testvectl () 384 { 385 int i, nerrors, k, ianswer, ntests; 386 long double (*fun1) (long double); 387 long double (*fun2) (long double, long double); 388 int (*fun3) (long double); 389 long double e; 390 union 391 { 392 long double d; 393 char c[12]; 394 } u, v; 395 396 /* This masks off fpu exceptions on i386. */ 397 /* setfpu(0x137f); */ 398 nerrors = 0; 399 ntests = 0; 400 MINFL = -INFINITYL; 401 MPIL = -PIL; 402 MPIO2L = -PIO2L; 403 MPIO4L = -PIO4L; 404 i = 0; 405 for (;;) 406 { 407 fun1 = test1[i].func; 408 if (fun1 == NULL) 409 break; 410 x1 = *(test1[i].arg1); 411 y = (*(fun1)) (x1); 412 answer = *(test1[i].answer); 413 if (test1[i].thresh == 0) 414 { 415 v.d = answer; 416 u.d = y; 417 if (memcmp(u.c, v.c, 10) != 0) 418 { 419 /* O.K. if both are NaNs of some sort. */ 420 if (__isnanl(v.d) && __isnanl(u.d)) 421 goto nxttest1; 422 goto wrongone; 423 } 424 else 425 goto nxttest1; 426 } 427 if (y != answer) 428 { 429 e = y - answer; 430 if (answer != 0.0L) 431 e = e / answer; 432 if (e < 0) 433 e = -e; 434 if (e > test1[i].thresh * MACHEPL) 435 { 436 wrongone: 437 printf ("%s (%.20Le) = %.20Le\n should be %.20Le\n", 438 test1[i].name, x1, y, answer); 439 nerrors += 1; 440 } 441 } 442 nxttest1: 443 ntests += 1; 444 i += 1; 445 } 446 447 i = 0; 448 for (;;) 449 { 450 fun2 = test2[i].func; 451 if (fun2 == NULL) 452 break; 453 x1 = *(test2[i].arg1); 454 x2 = *(test2[i].arg2); 455 y = (*(fun2)) (x1, x2); 456 answer = *(test2[i].answer); 457 if (test2[i].thresh == 0) 458 { 459 v.d = answer; 460 u.d = y; 461 if (memcmp(u.c, v.c, 10) != 0) 462 { 463 /* O.K. if both are NaNs of some sort. */ 464 if (__isnanl(v.d) && __isnanl(u.d)) 465 goto nxttest2; 466 goto wrongtwo; 467 } 468 else 469 goto nxttest2; 470 } 471 if (y != answer) 472 { 473 e = y - answer; 474 if (answer != 0.0L) 475 e = e / answer; 476 if (e < 0) 477 e = -e; 478 if (e > test2[i].thresh * MACHEPL) 479 { 480 wrongtwo: 481 printf ("%s (%.20Le, %.20Le) = %.20Le\n should be %.20Le\n", 482 test2[i].name, x1, x2, y, answer); 483 nerrors += 1; 484 } 485 } 486 nxttest2: 487 ntests += 1; 488 i += 1; 489 } 490 491 492 i = 0; 493 for (;;) 494 { 495 fun3 = test3[i].func; 496 if (fun3 == NULL) 497 break; 498 x1 = *(test3[i].arg1); 499 k = (*(fun3)) (x1); 500 ianswer = test3[i].ianswer; 501 if (k != ianswer) 502 { 503 printf ("%s (%.20Le) = %d\n should be. %d\n", 504 test3[i].name, x1, k, ianswer); 505 nerrors += 1; 506 } 507 ntests += 1; 508 i += 1; 509 } 510 511 printf ("%d errors in %d tests\n", nerrors, ntests); 512 return (nerrors); 513 } 514 #endif /* LDBL_MANT_DIG == 64 */ 515