5 enum {LESS
,EQUAL
,GREATER
,UNORD
};
7 #define TEST(f,want) do{ \
9 feclearexcept(FE_ALL_EXCEPT); \
11 e = fetestexcept(FE_ALL_EXCEPT); \
13 t_error(#f " failed: got %d want %d\n", r, (want)); \
15 t_error(#f " raised the invalid exception\n"); \
19 #define T(a,b,rel) do{ \
20 TEST(isunordered(a, b), rel == UNORD); \
21 TEST(isless(a, b), rel == LESS); \
22 TEST(islessequal(a, b), rel == LESS || rel == EQUAL); \
23 TEST(islessgreater(a, b), rel == LESS || rel == GREATER); \
24 TEST(isgreater(a, b), rel == GREATER); \
25 TEST(isgreaterequal(a, b), rel == GREATER || rel == EQUAL); \
30 #pragma STDC FENV_ACCESS ON
31 volatile double huge
= DBL_MAX
;
32 volatile double tiny
= DBL_MIN
;
33 volatile double eps
= DBL_EPSILON
;
34 volatile float hugef
= FLT_MAX
;
35 volatile float tinyf
= FLT_MIN
;
36 volatile float epsf
= FLT_EPSILON
;
37 volatile long double hugel
= LDBL_MAX
;
38 volatile long double tinyl
= LDBL_MIN
;
39 volatile long double epsl
= LDBL_EPSILON
;
44 T(nan
, nan
+1.0, UNORD
);
45 T(nan
, nan
+1.0L, UNORD
);
48 T(1.0, 1.0+eps
, LESS
);
49 T(1.0+eps
, 1.0, GREATER
);
50 T(huge
-1, huge
, EQUAL
);
51 T(huge
, huge
*huge
, LESS
);
54 T(tiny
, 2*tiny
, LESS
);
55 T(tiny
*0x1p
-9, tiny
*0x1p
-8, LESS
);
58 T(1.0f
, 1.0f
+epsf
, LESS
);
59 T(1.0f
+epsf
, 1.0f
, GREATER
);
60 T(hugef
-1, hugef
, EQUAL
);
61 T(hugef
, hugef
*hugef
, LESS
);
62 T(-0.0f
, 0.0f
, EQUAL
);
63 T(-tinyf
, 0.0f
, LESS
);
64 T(tinyf
, 2*tinyf
, LESS
);
65 T(tinyf
*0x1p
-9f
, tinyf
*0x1p
-8f
, LESS
);
68 T(1.0L, 1.0L+epsl
, LESS
);
69 T(1.0L+epsl
, 1.0L, GREATER
);
70 T(hugel
-1, hugel
, EQUAL
);
71 T(hugel
, hugel
*hugel
, LESS
);
72 T(-0.0L, 0.0L, EQUAL
);
73 T(-tinyl
, 0.0L, LESS
);
74 T(tinyl
, 2*tinyl
, LESS
);
75 T(tinyl
*0x1p
-9L, tinyl
*0x1p
-8L, LESS
);
77 #if FLT_EVAL_METHOD == 2
78 T(huge
*huge
, huge
*huge
*2, LESS
);
79 T(tiny
*tiny
*0.5, tiny
*tiny
, LESS
);
80 T(-tiny
*tiny
, 0.0, LESS
);
81 T(1.0, 1.0+eps
*0.25, LESS
);
83 T(huge
*huge
, huge
*huge
*2, EQUAL
);
84 T(tiny
*tiny
*0.5, tiny
*tiny
, EQUAL
);
85 T(-tiny
*tiny
, 0.0, EQUAL
);
86 T(1.0, 1.0+eps
*0.25, EQUAL
);
89 #if FLT_EVAL_METHOD >= 1
90 T(hugef
*hugef
, hugef
*hugef
*2, LESS
);
91 T(tiny
*tiny
*0.5f
, tiny
*tiny
, LESS
);
92 T(-tiny
*tiny
, 0.0f
, LESS
);
93 T(1.0f
, 1.0f
+epsf
*0.25f
, LESS
);
95 T(hugef
*hugef
, hugef
*hugef
*2, EQUAL
);
96 T(tiny
*tiny
*0.5f
, tiny
*tiny
, EQUAL
);
97 T(-tiny
*tiny
, 0.0f
, EQUAL
);
98 T(1.0f
, 1.0f
+epsf
*0.25f
, EQUAL
);
101 T(hugel
*hugel
, hugel
*hugel
*2, EQUAL
);
102 T(tinyl
*tinyl
*0.5L, tinyl
*tinyl
, EQUAL
);
103 T(-tinyl
*tinyl
, 0.0L, EQUAL
);
104 T(1.0L, 1.0L+epsl
*0.25L, EQUAL
);