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#include "float.h"
44#include "dbl_float.h"
45
46
47
48
49int
50dbl_fcmp (dbl_floating_point * leftptr, dbl_floating_point * rightptr,
51 unsigned int cond, unsigned int *status)
52
53
54
55 {
56 register unsigned int leftp1, leftp2, rightp1, rightp2;
57 register int xorresult;
58
59
60 Dbl_copyfromptr(leftptr,leftp1,leftp2);
61 Dbl_copyfromptr(rightptr,rightp1,rightp2);
62
63
64
65 if( (Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)
66 || (Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT) )
67 {
68
69
70
71 if( ((Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)
72 && Dbl_isnotzero_mantissa(leftp1,leftp2)
73 && (Exception(cond) || Dbl_isone_signaling(leftp1)))
74 ||
75 ((Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT)
76 && Dbl_isnotzero_mantissa(rightp1,rightp2)
77 && (Exception(cond) || Dbl_isone_signaling(rightp1))) )
78 {
79 if( Is_invalidtrap_enabled() ) {
80 Set_status_cbit(Unordered(cond));
81 return(INVALIDEXCEPTION);
82 }
83 else Set_invalidflag();
84 Set_status_cbit(Unordered(cond));
85 return(NOEXCEPTION);
86 }
87
88
89 else if( ((Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)
90 && Dbl_isnotzero_mantissa(leftp1,leftp2))
91 ||
92 ((Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT)
93 && Dbl_isnotzero_mantissa(rightp1,rightp2)) )
94 {
95
96 Set_status_cbit(Unordered(cond));
97 return(NOEXCEPTION);
98 }
99
100 }
101
102
103 Dbl_xortointp1(leftp1,rightp1,xorresult);
104 if( xorresult < 0 )
105 {
106
107
108 if( Dbl_iszero_exponentmantissa(leftp1,leftp2)
109 && Dbl_iszero_exponentmantissa(rightp1,rightp2) )
110 {
111 Set_status_cbit(Equal(cond));
112 }
113 else if( Dbl_isone_sign(leftp1) )
114 {
115 Set_status_cbit(Lessthan(cond));
116 }
117 else
118 {
119 Set_status_cbit(Greaterthan(cond));
120 }
121 }
122
123
124 else if(Dbl_isequal(leftp1,leftp2,rightp1,rightp2))
125 {
126 Set_status_cbit(Equal(cond));
127 }
128 else if( Dbl_iszero_sign(leftp1) )
129 {
130
131 if( Dbl_allp1(leftp1) < Dbl_allp1(rightp1) )
132 {
133 Set_status_cbit(Lessthan(cond));
134 }
135 else if( Dbl_allp1(leftp1) > Dbl_allp1(rightp1) )
136 {
137 Set_status_cbit(Greaterthan(cond));
138 }
139 else
140 {
141
142
143 if( Dbl_allp2(leftp2) < Dbl_allp2(rightp2) )
144 {
145 Set_status_cbit(Lessthan(cond));
146 }
147 else
148 {
149 Set_status_cbit(Greaterthan(cond));
150 }
151 }
152 }
153 else
154 {
155
156
157
158 if( Dbl_allp1(leftp1) > Dbl_allp1(rightp1) )
159 {
160 Set_status_cbit(Lessthan(cond));
161 }
162 else if( Dbl_allp1(leftp1) < Dbl_allp1(rightp1) )
163 {
164 Set_status_cbit(Greaterthan(cond));
165 }
166 else
167 {
168
169
170 if( Dbl_allp2(leftp2) > Dbl_allp2(rightp2) )
171 {
172 Set_status_cbit(Lessthan(cond));
173 }
174 else
175 {
176 Set_status_cbit(Greaterthan(cond));
177 }
178 }
179 }
180 return(NOEXCEPTION);
181 }
182