Fix order of jn() arguments in error message
[libc-test.git] / src / math / isless.c
blob4ce1bc6907aaa8817cdb84f2c9e4c01c4a8882a9
1 #include <math.h>
2 #include "mtest.h"
3 #include "test.h"
5 enum {LESS,EQUAL,GREATER,UNORD};
7 #define TEST(f,want) do{ \
8 int r, e; \
9 feclearexcept(FE_ALL_EXCEPT); \
10 r = (f); \
11 e = fetestexcept(FE_ALL_EXCEPT); \
12 if (r != (want)) \
13 t_error(#f " failed: got %d want %d\n", r, (want)); \
14 if (e & INVALID) \
15 t_error(#f " raised the invalid exception\n"); \
16 }while(0)
18 #undef T
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); \
26 }while(0)
28 int main()
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;
41 T(nan, 1.0, UNORD);
42 T(1.0, nan, UNORD);
43 T(nan, nan, UNORD);
44 T(nan, nan+1.0, UNORD);
45 T(nan, nan+1.0L, UNORD);
47 T(1.0, 1.1, LESS);
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);
52 T(-0.0, 0.0, EQUAL);
53 T(-tiny, 0.0, LESS);
54 T(tiny, 2*tiny, LESS);
55 T(tiny*0x1p-9, tiny*0x1p-8, LESS);
57 T(1.0f, 1.1f, 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);
67 T(1.0L, 1.1L, 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);
82 #else
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);
87 #endif
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);
94 #else
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);
99 #endif
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);
106 return t_status;