1 /* Basic test of runtime equality comparisons using simple values that
2 are not affected by rounding. */
3
4 #include <stdlib.h>
5 #include "dfp-dbg.h"
6
7 #define PASTE2(A,B) A ## B
8 #define PASTE(A,B) PASTE2(A,B)
9
10 #undef FAILURE
11 #ifdef DBG
12 #define FAILURE(OP,KIND) \
13 { printf ("failed at line %d: %s for %s values\n", __LINE__, OP, KIND); \
14 failures++; }
15 #else
16 #define FAILURE(OP,KIND) __builtin_abort ();
17 #endif
18
19 #ifndef WIDTH
20 #error define WIDTH as decimal float size in bytes
21 #endif
22
23 #if WIDTH == 32
24 #define DTYPE _Decimal32
25 #define SUFFIX DF
26 #elif WIDTH == 64
27 #define DTYPE _Decimal64
28 #define SUFFIX DD
29 #elif WIDTH == 128
30 #define DTYPE _Decimal128
31 #define SUFFIX DL
32 #elif WIDTH == 0
33 /* This is for testing the test using a type known to work. */
34 #define DTYPE double
35 #define SUFFIX
36 #else
37 #error invalid width for decimal float type
38 #endif
39
40 DTYPE m_two = PASTE(-2.0, SUFFIX);
41 DTYPE m_one = PASTE(-1.0, SUFFIX);
42 DTYPE zero = PASTE(0.0, SUFFIX);
43 DTYPE one = PASTE(1.0, SUFFIX);
44 DTYPE two = PASTE(2.0, SUFFIX);
45
46 void
test_compares(void)47 test_compares (void)
48 {
49 DTYPE x = one;
50 DTYPE y = zero;
51 DTYPE z = m_one;
52
53 /* Equal to: comparisons against equal values. */
54
55 if (! (x == one)) FAILURE ("==", "equal")
56 if (! (y == zero)) FAILURE ("==", "equal")
57 if (! (z == m_one)) FAILURE ("==", "equal")
58
59 /* Equal to: comparisons against lesser values. */
60
61 if (x == m_one) FAILURE ("==", "lesser")
62 if (x == zero) FAILURE ("==", "lesser")
63 if (y == m_one) FAILURE ("==", "lesser")
64 if (z == m_two) FAILURE ("==", "lesser")
65
66 /* Equal to: comparisons against greater values. */
67
68 if (x == two) FAILURE ("==", "greater")
69 if (y == one) FAILURE ("==", "greater")
70 if (z == zero) FAILURE ("==", "greater")
71 if (z == one) FAILURE ("==", "greater")
72
73 /* Not equal to: comparisons against equal values. */
74
75 if (x != one) FAILURE ("!=", "equal")
76 if (y != zero) FAILURE ("!=", "equal")
77 if (z != m_one) FAILURE ("!=", "equal")
78
79 /* Not equal to: comparisons against lesser values. */
80
81 if (! (x != m_one)) FAILURE ("!=", "lesser")
82 if (! (x != zero)) FAILURE ("!=", "lesser")
83 if (! (y != m_one)) FAILURE ("!=", "lesser")
84 if (! (z != m_two)) FAILURE ("!=", "lesser")
85
86 /* Not equal to: comparisons against greater values. */
87
88 if (! (x != m_one)) FAILURE ("!=", "greater")
89 if (! (x != zero)) FAILURE ("!=", "greater")
90 if (! (y != m_one)) FAILURE ("!=", "greater")
91 if (! (z != m_two)) FAILURE ("!=", "greater")
92 }
93