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