1 /* 2 * Copyright (c) 1994 Cygnus Support. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * and/or other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to 11 * endorse or promote products derived from this software without 12 * specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 #define _GNU_SOURCE 18 #define HAVE_FLOAT 1 19 #define X(x) (char *)x 20 21 #include <math.h> 22 #include <float.h> 23 #include <stdio.h> 24 #include <stdint.h> 25 #include <stdlib.h> 26 27 #ifdef INCLUDE_GENERATE 28 #define TEST_CONST 29 #else 30 #define TEST_CONST const 31 #endif 32 33 /* FIXME FIXME FIXME: 34 Neither of __ieee_{float,double}_shape_type seem to be used anywhere 35 except in libm/test. If that is the case, please delete these from here. 36 If that is not the case, please insert documentation here describing why 37 they're needed. */ 38 39 #ifdef __IEEE_BIG_ENDIAN 40 41 typedef union 42 { 43 double value; 44 struct 45 { 46 unsigned int sign : 1; 47 unsigned int exponent: 11; 48 unsigned int fraction0:4; 49 unsigned int fraction1:16; 50 unsigned int fraction2:16; 51 unsigned int fraction3:16; 52 53 } number; 54 struct 55 { 56 unsigned int sign : 1; 57 unsigned int exponent: 11; 58 unsigned int quiet:1; 59 unsigned int function0:3; 60 unsigned int function1:16; 61 unsigned int function2:16; 62 unsigned int function3:16; 63 } nan; 64 struct 65 { 66 uint32_t msw; 67 uint32_t lsw; 68 } parts; 69 int32_t aslong[2]; 70 } __ieee_double_shape_type; 71 72 #else 73 74 typedef union 75 { 76 double value; 77 struct 78 { 79 #ifdef __SMALL_BITFIELDS 80 uint32_t fraction3:16; 81 uint32_t fraction2:16; 82 uint32_t fraction1:16; 83 uint32_t fraction0: 4; 84 #else 85 uint32_t fraction1:32; 86 uint32_t fraction0:20; 87 #endif 88 uint32_t exponent :11; 89 uint32_t sign : 1; 90 } number; 91 struct 92 { 93 #ifdef __SMALL_BITFIELDS 94 uint32_t function3:16; 95 uint32_t function2:16; 96 uint32_t function1:16; 97 uint32_t function0:3; 98 #else 99 uint32_t function1:32; 100 uint32_t function0:19; 101 #endif 102 uint32_t quiet:1; 103 uint32_t exponent: 11; 104 uint32_t sign : 1; 105 } nan; 106 struct 107 { 108 uint32_t lsw; 109 uint32_t msw; 110 } parts; 111 112 int32_t aslong[2]; 113 114 } __ieee_double_shape_type; 115 116 #endif /* __IEEE_LITTLE_ENDIAN */ 117 118 #ifdef __IEEE_BIG_ENDIAN 119 120 typedef union 121 { 122 float value; 123 struct 124 { 125 uint32_t sign : 1; 126 uint32_t exponent: 8; 127 uint32_t fraction0: 7; 128 uint32_t fraction1: 16; 129 } number; 130 struct 131 { 132 uint32_t sign:1; 133 uint32_t exponent:8; 134 uint32_t quiet:1; 135 uint32_t function0:6; 136 uint32_t function1:16; 137 } nan; 138 uint32_t p1; 139 140 } __ieee_float_shape_type; 141 142 #else 143 144 typedef union 145 { 146 float value; 147 struct 148 { 149 uint32_t fraction0: 7; 150 uint32_t fraction1: 16; 151 uint32_t exponent: 8; 152 uint32_t sign : 1; 153 } number; 154 struct 155 { 156 uint32_t function1:16; 157 uint32_t function0:6; 158 uint32_t quiet:1; 159 uint32_t exponent:8; 160 uint32_t sign:1; 161 } nan; 162 int32_t p1; 163 164 } __ieee_float_shape_type; 165 166 #endif /* __IEEE_LITTLE_ENDIAN */ 167 168 extern int inacc; 169 extern int redo; 170 extern int reduce; 171 extern int verbose; 172 173 void checkf(); 174 void enter(); 175 176 177 double translate_from(); 178 179 typedef struct 180 { 181 uint32_t msw, lsw; 182 } question_struct_type; 183 184 185 typedef TEST_CONST struct 186 { 187 char error_bit; 188 char errno_val; 189 char merror; 190 int line; 191 192 question_struct_type qs[3]; 193 } one_line_type; 194 195 196 #define MVEC_START(x) one_line_type x[] = { 197 #define MVEC_END 0,}; 198 199 200 int mag_of_error (double, double); 201 int fmag_of_error (float, float); 202 203 204 #define ERROR_PERFECT 20 205 #define ERROR_FAIL -1 206 207 #define AAAA 15 208 #define AAA 10 209 #define AA 6 210 #define A 5 211 #define B 3 212 #define C 1 213 #define VECOPEN(x,f) \ 214 {\ 215 char buffer[100];\ 216 sprintf(buffer,"%s_vec.c",x);\ 217 f = fopen(buffer,"w");\ 218 if (!f) { perror(buffer); exit(1); } \ 219 fprintf(f,"#include \"test.h\"\n");\ 220 fprintf(f," one_line_type %s_vec[] = {\n", x);\ 221 } 222 223 #define VECCLOSE(f,name,args)\ 224 {\ 225 fprintf(f,"0,};\n"); \ 226 fprintf(f,"test_%s(int m) {run_vector_1(m,%s_vec,(char *)(%s),\"%s\",\"%s\"); } \n",\ 227 name,\ 228 name,name,name,args);\ 229 fclose(f);\ 230 } 231 232 233 234 typedef TEST_CONST struct 235 { 236 int line; 237 238 char *string; 239 double value; 240 int endscan; 241 } double_type; 242 243 #define ENDSCAN_MASK 0x7f 244 #define ENDSCAN_IS_ZERO 0x80 245 #define ENDSCAN_IS_INF 0x80 246 247 typedef TEST_CONST struct { 248 long int value; 249 char end; 250 char errno_val; 251 } int_scan_type; 252 253 typedef TEST_CONST struct 254 { 255 int line; 256 int_scan_type octal; 257 int_scan_type decimal; 258 int_scan_type hex; 259 int_scan_type normal; 260 int_scan_type alphabetical; 261 char *string; 262 } int_type; 263 264 265 typedef TEST_CONST struct 266 { 267 int line; 268 double value; 269 char *estring; 270 int e1; 271 int e2; 272 int e3; 273 char *fstring; 274 int f1; 275 int f2; 276 int f3; 277 char *gstring; 278 int g1; 279 char *gfstring; 280 } ddouble_type; 281 282 typedef TEST_CONST struct 283 { 284 int line; 285 double value; 286 char *result; 287 char *format_string; 288 int mag; 289 } sprint_double_type; 290 291 292 typedef TEST_CONST struct 293 { 294 int line; 295 int32_t value; 296 char *result; 297 char *format_string; 298 } sprint_int_type; 299 300 301 void test_ieee (void); 302 void test_math2 (void); 303 void test_math (int vector); 304 void test_string (void); 305 void test_is (void); 306 void test_cvt (void); 307 308 void line (int); 309 310 void test_mok (double, double, int); 311 void test_mfok (float, float, int); 312 void test_iok (int, int); 313 void test_eok (int, int); 314 void test_sok (char *, char*); 315 void test_scok (char *, char*, int); 316 void test_scok2 (char *, char*, char*, int); 317 void newfunc (const char *); 318 319 void 320 run_vector_1 (int vector, 321 one_line_type *p, 322 char *func, 323 char *name, 324 char *args); 325 void 326 test_acos(int vector); 327 328 void 329 test_acosf(int vector); 330 331 void 332 test_acosh(int vector); 333 334 void 335 test_acoshf(int vector); 336 337 void 338 test_asin(int vector); 339 340 void 341 test_asinf(int vector); 342 343 void 344 test_asinh(int vector); 345 346 void 347 test_asinhf(int vector); 348 349 void 350 test_atan(int vector); 351 352 void 353 test_atan2(int vector); 354 355 void 356 test_atan2f(int vector); 357 358 void 359 test_atanf(int vector); 360 361 void 362 test_atanh(int vector); 363 364 void 365 test_atanhf(int vector); 366 367 void 368 test_ceil(int vector); 369 370 void 371 test_ceilf(int vector); 372 373 void 374 test_copysign(int vector); 375 376 void 377 test_copysignf(int vector); 378 379 void 380 test_cos(int vector); 381 382 void 383 test_cosf(int vector); 384 385 void 386 test_cosh(int vector); 387 388 void 389 test_coshf(int vector); 390 391 void 392 test_erf(int vector); 393 394 void 395 test_erfc(int vector); 396 397 void 398 test_erfcf(int vector); 399 400 void 401 test_erff(int vector); 402 403 void 404 test_exp(int vector); 405 406 void 407 test_expf(int vector); 408 409 void 410 test_fabs(int vector); 411 412 void 413 test_fabsf(int vector); 414 415 void 416 test_floor(int vector); 417 418 void 419 test_floorf(int vector); 420 421 void 422 test_fmod(int vector); 423 424 void 425 test_fmodf(int vector); 426 427 void 428 test_gamma(int vector); 429 430 void 431 test_gammaf(int vector); 432 433 void 434 test_hypot(int vector); 435 436 void 437 test_hypotf(int vector); 438 439 void 440 test_issignaling(int vector); 441 442 void 443 test_j0(int vector); 444 445 void 446 test_j0f(int vector); 447 448 void 449 test_j1(int vector); 450 451 void 452 test_j1f(int vector); 453 454 void 455 test_jn(int vector); 456 457 void 458 test_jnf(int vector); 459 460 void 461 test_log(int vector); 462 463 void 464 test_log10(int vector); 465 466 void 467 test_log10f(int vector); 468 469 void 470 test_log1p(int vector); 471 472 void 473 test_log1pf(int vector); 474 475 void 476 test_log2(int vector); 477 478 void 479 test_log2f(int vector); 480 481 void 482 test_logf(int vector); 483 484 void 485 test_modf(int vector); 486 487 void 488 test_modff(int vector); 489 490 void 491 test_pow_vec(int vector); 492 493 void 494 test_powf_vec(int vector); 495 496 void 497 test_scalb(int vector); 498 499 void 500 test_scalbf(int vector); 501 502 void 503 test_scalbn(int vector); 504 505 void 506 test_scalbnf(int vector); 507 508 void 509 test_sin(int vector); 510 511 void 512 test_sinf(int vector); 513 514 void 515 test_sinh(int vector); 516 517 void 518 test_sinhf(int vector); 519 520 void 521 test_sqrt(int vector); 522 523 void 524 test_sqrtf(int vector); 525 526 void 527 test_tan(int vector); 528 529 void 530 test_tanf(int vector); 531 532 void 533 test_tanh(int vector); 534 535 void 536 test_tanhf(int vector); 537 538 void 539 test_trunc(int vector); 540 541 void 542 test_truncf(int vector); 543 544 void 545 test_y0(int vector); 546 547 void 548 test_y0f(int vector); 549 550 void 551 test_y1(int vector); 552 553 void 554 test_y1f(int vector); 555 556 void 557 test_yn(int vector); 558 559 void 560 test_ynf(int vector); 561 562