| 1 |
/* Tests for _FloatN / _FloatNx types: compile and execution tests for |
| 2 |
type-generic built-in functions: __builtin_fpclassify. Before |
| 3 |
including this file, define WIDTH as the value N; define EXT to 1 |
| 4 |
for _FloatNx and 0 for _FloatN. */ |
| 5 |
|
| 6 |
#define __STDC_WANT_IEC_60559_TYPES_EXT__ |
| 7 |
#include <float.h> |
| 8 |
|
| 9 |
#define CONCATX(X, Y) X ## Y |
| 10 |
#define CONCAT(X, Y) CONCATX (X, Y) |
| 11 |
#define CONCAT3(X, Y, Z) CONCAT (CONCAT (X, Y), Z) |
| 12 |
#define CONCAT4(W, X, Y, Z) CONCAT (CONCAT (CONCAT (W, X), Y), Z) |
| 13 |
|
| 14 |
#if EXT |
| 15 |
# define TYPE CONCAT3 (_Float, WIDTH, x) |
| 16 |
# define CST(C) CONCAT4 (C, f, WIDTH, x) |
| 17 |
# define MAX CONCAT3 (FLT, WIDTH, X_MAX) |
| 18 |
# define MIN CONCAT3 (FLT, WIDTH, X_MIN) |
| 19 |
# define TRUE_MIN CONCAT3 (FLT, WIDTH, X_TRUE_MIN) |
| 20 |
#else |
| 21 |
# define TYPE CONCAT (_Float, WIDTH) |
| 22 |
# define CST(C) CONCAT3 (C, f, WIDTH) |
| 23 |
# define MAX CONCAT3 (FLT, WIDTH, _MAX) |
| 24 |
# define MIN CONCAT3 (FLT, WIDTH, _MIN) |
| 25 |
# define TRUE_MIN CONCAT3 (FLT, WIDTH, _TRUE_MIN) |
| 26 |
#endif |
| 27 |
|
| 28 |
extern void exit (int); |
| 29 |
extern void abort (void); |
| 30 |
|
| 31 |
#define FP_NAN 0 |
| 32 |
#define FP_INFINITE 1 |
| 33 |
#define FP_ZERO 2 |
| 34 |
#define FP_SUBNORMAL 3 |
| 35 |
#define FP_NORMAL 4 |
| 36 |
|
| 37 |
#define fpclassify(X) __builtin_fpclassify (FP_NAN, FP_INFINITE, \ |
| 38 |
FP_NORMAL, FP_SUBNORMAL, \ |
| 39 |
FP_ZERO, (X)) |
| 40 |
|
| 41 |
volatile TYPE inf = __builtin_inf (), nanval = __builtin_nan (""); |
| 42 |
volatile TYPE neginf = -__builtin_inf (), negnanval = -__builtin_nan (""); |
| 43 |
volatile TYPE zero = CST (0.0), negzero = -CST (0.0), one = CST (1.0); |
| 44 |
volatile TYPE max = MAX, negmax = -MAX, min = MIN, negmin = -MIN; |
| 45 |
volatile TYPE true_min = TRUE_MIN, negtrue_min = -TRUE_MIN; |
| 46 |
|
| 47 |
/* Allow for any optimizations of comparisons involving the result of |
| 48 |
fpclassify by also testing case where result is stored in a |
| 49 |
volatile variable and so the comparison cannot be optimized. */ |
| 50 |
#define CHECK_FPCLASSIFY(VAL, EXP) \ |
| 51 |
do \ |
| 52 |
{ \ |
| 53 |
volatile int c; \ |
| 54 |
if (fpclassify (VAL) != (EXP)) \ |
| 55 |
abort (); \ |
| 56 |
c = fpclassify (VAL); \ |
| 57 |
if (c != (EXP)) \ |
| 58 |
abort (); \ |
| 59 |
} \ |
| 60 |
while (0) |
| 61 |
|
| 62 |
int |
| 63 |
main (void) |
| 64 |
{ |
| 65 |
CHECK_FPCLASSIFY (inf, FP_INFINITE); |
| 66 |
CHECK_FPCLASSIFY (neginf, FP_INFINITE); |
| 67 |
CHECK_FPCLASSIFY (nanval, FP_NAN); |
| 68 |
CHECK_FPCLASSIFY (negnanval, FP_NAN); |
| 69 |
CHECK_FPCLASSIFY (zero, FP_ZERO); |
| 70 |
CHECK_FPCLASSIFY (negzero, FP_ZERO); |
| 71 |
CHECK_FPCLASSIFY (one, FP_NORMAL); |
| 72 |
CHECK_FPCLASSIFY (max, FP_NORMAL); |
| 73 |
CHECK_FPCLASSIFY (negmax, FP_NORMAL); |
| 74 |
CHECK_FPCLASSIFY (min, FP_NORMAL); |
| 75 |
CHECK_FPCLASSIFY (negmin, FP_NORMAL); |
| 76 |
CHECK_FPCLASSIFY (true_min, FP_SUBNORMAL); |
| 77 |
CHECK_FPCLASSIFY (negtrue_min, FP_SUBNORMAL); |
| 78 |
exit (0); |
| 79 |
} |