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 <ieeefp.h> 24 #include <stdio.h> 25 #include <stdint.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 fprintf(f,"#include \"test.h\"\n");\ 219 fprintf(f," one_line_type %s_vec[] = {\n", x);\ 220 } 221 222 #define VECCLOSE(f,name,args)\ 223 {\ 224 fprintf(f,"0,};\n"); \ 225 fprintf(f,"test_%s(int m) {run_vector_1(m,%s_vec,(char *)(%s),\"%s\",\"%s\"); } \n",\ 226 name,\ 227 name,name,name,args);\ 228 fclose(f);\ 229 } 230 231 232 233 typedef TEST_CONST struct 234 { 235 int line; 236 237 char *string; 238 double value; 239 int endscan; 240 } double_type; 241 242 #define ENDSCAN_MASK 0x7f 243 #define ENDSCAN_IS_ZERO 0x80 244 #define ENDSCAN_IS_INF 0x80 245 246 typedef TEST_CONST struct { 247 long int value; 248 char end; 249 char errno_val; 250 } int_scan_type; 251 252 typedef TEST_CONST struct 253 { 254 int line; 255 int_scan_type octal; 256 int_scan_type decimal; 257 int_scan_type hex; 258 int_scan_type normal; 259 int_scan_type alphabetical; 260 char *string; 261 } int_type; 262 263 264 typedef TEST_CONST struct 265 { 266 int line; 267 double value; 268 char *estring; 269 int e1; 270 int e2; 271 int e3; 272 char *fstring; 273 int f1; 274 int f2; 275 int f3; 276 char *gstring; 277 int g1; 278 char *gfstring; 279 } ddouble_type; 280 281 typedef TEST_CONST struct 282 { 283 int line; 284 double value; 285 char *result; 286 char *format_string; 287 int mag; 288 } sprint_double_type; 289 290 291 typedef TEST_CONST struct 292 { 293 int line; 294 int32_t value; 295 char *result; 296 char *format_string; 297 } sprint_int_type; 298 299 300 void test_ieee (void); 301 void test_math2 (void); 302 void test_math (int vector); 303 void test_string (void); 304 void test_is (void); 305 void test_cvt (void); 306 307 void line (int); 308 309 void test_mok (double, double, int); 310 void test_mfok (float, float, int); 311 void test_iok (int, int); 312 void test_eok (int, int); 313 void test_sok (char *, char*); 314 void test_scok (char *, char*, int); 315 void test_scok2 (char *, char*, char*, int); 316 void newfunc (const char *); 317 318 void 319 run_vector_1 (int vector, 320 one_line_type *p, 321 char *func, 322 char *name, 323 char *args); 324 void 325 test_acos(int vector); 326 327 void 328 test_acosf(int vector); 329 330 void 331 test_acosh(int vector); 332 333 void 334 test_acoshf(int vector); 335 336 void 337 test_asin(int vector); 338 339 void 340 test_asinf(int vector); 341 342 void 343 test_asinh(int vector); 344 345 void 346 test_asinhf(int vector); 347 348 void 349 test_atan(int vector); 350 351 void 352 test_atan2(int vector); 353 354 void 355 test_atan2f(int vector); 356 357 void 358 test_atanf(int vector); 359 360 void 361 test_atanh(int vector); 362 363 void 364 test_atanhf(int vector); 365 366 void 367 test_ceil(int vector); 368 369 void 370 test_ceilf(int vector); 371 372 void 373 test_copysign(int vector); 374 375 void 376 test_copysignf(int vector); 377 378 void 379 test_cos(int vector); 380 381 void 382 test_cosf(int vector); 383 384 void 385 test_cosh(int vector); 386 387 void 388 test_coshf(int vector); 389 390 void 391 test_erf(int vector); 392 393 void 394 test_erfc(int vector); 395 396 void 397 test_erfcf(int vector); 398 399 void 400 test_erff(int vector); 401 402 void 403 test_exp(int vector); 404 405 void 406 test_expf(int vector); 407 408 void 409 test_fabs(int vector); 410 411 void 412 test_fabsf(int vector); 413 414 void 415 test_floor(int vector); 416 417 void 418 test_floorf(int vector); 419 420 void 421 test_fmod(int vector); 422 423 void 424 test_fmodf(int vector); 425 426 void 427 test_gamma(int vector); 428 429 void 430 test_gammaf(int vector); 431 432 void 433 test_hypot(int vector); 434 435 void 436 test_hypotf(int vector); 437 438 void 439 test_issignaling(int vector); 440 441 void 442 test_j0(int vector); 443 444 void 445 test_j0f(int vector); 446 447 void 448 test_j1(int vector); 449 450 void 451 test_j1f(int vector); 452 453 void 454 test_jn(int vector); 455 456 void 457 test_jnf(int vector); 458 459 void 460 test_log(int vector); 461 462 void 463 test_log10(int vector); 464 465 void 466 test_log10f(int vector); 467 468 void 469 test_log1p(int vector); 470 471 void 472 test_log1pf(int vector); 473 474 void 475 test_log2(int vector); 476 477 void 478 test_log2f(int vector); 479 480 void 481 test_logf(int vector); 482 483 void 484 test_modf(int vector); 485 486 void 487 test_modff(int vector); 488 489 void 490 test_pow_vec(int vector); 491 492 void 493 test_powf_vec(int vector); 494 495 void 496 test_scalb(int vector); 497 498 void 499 test_scalbf(int vector); 500 501 void 502 test_scalbn(int vector); 503 504 void 505 test_scalbnf(int vector); 506 507 void 508 test_sin(int vector); 509 510 void 511 test_sinf(int vector); 512 513 void 514 test_sinh(int vector); 515 516 void 517 test_sinhf(int vector); 518 519 void 520 test_sqrt(int vector); 521 522 void 523 test_sqrtf(int vector); 524 525 void 526 test_tan(int vector); 527 528 void 529 test_tanf(int vector); 530 531 void 532 test_tanh(int vector); 533 534 void 535 test_tanhf(int vector); 536 537 void 538 test_trunc(int vector); 539 540 void 541 test_truncf(int vector); 542 543 void 544 test_y0(int vector); 545 546 void 547 test_y0f(int vector); 548 549 void 550 test_y1(int vector); 551 552 void 553 test_y1f(int vector); 554 555 void 556 test_y1f(int vector); 557 558 void 559 test_ynf(int vector); 560 561