This source file includes following definitions.
- sgl_frem
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 #include "float.h"
31 #include "sgl_float.h"
32
33
34
35
36
37 int
38 sgl_frem (sgl_floating_point * srcptr1, sgl_floating_point * srcptr2,
39 sgl_floating_point * dstptr, unsigned int *status)
40 {
41 register unsigned int opnd1, opnd2, result;
42 register int opnd1_exponent, opnd2_exponent, dest_exponent, stepcount;
43 register boolean roundup = FALSE;
44
45 opnd1 = *srcptr1;
46 opnd2 = *srcptr2;
47
48
49
50 if ((opnd1_exponent = Sgl_exponent(opnd1)) == SGL_INFINITY_EXPONENT) {
51 if (Sgl_iszero_mantissa(opnd1)) {
52 if (Sgl_isnotnan(opnd2)) {
53
54 if (Is_invalidtrap_enabled())
55 return(INVALIDEXCEPTION);
56 Set_invalidflag();
57 Sgl_makequietnan(result);
58 *dstptr = result;
59 return(NOEXCEPTION);
60 }
61 }
62 else {
63
64
65
66 if (Sgl_isone_signaling(opnd1)) {
67
68 if (Is_invalidtrap_enabled())
69 return(INVALIDEXCEPTION);
70
71 Set_invalidflag();
72 Sgl_set_quiet(opnd1);
73 }
74
75
76
77 else if (Sgl_is_signalingnan(opnd2)) {
78
79 if (Is_invalidtrap_enabled())
80 return(INVALIDEXCEPTION);
81
82 Set_invalidflag();
83 Sgl_set_quiet(opnd2);
84 *dstptr = opnd2;
85 return(NOEXCEPTION);
86 }
87
88
89
90 *dstptr = opnd1;
91 return(NOEXCEPTION);
92 }
93 }
94
95
96
97 if ((opnd2_exponent = Sgl_exponent(opnd2)) == SGL_INFINITY_EXPONENT) {
98 if (Sgl_iszero_mantissa(opnd2)) {
99
100
101
102 *dstptr = opnd1;
103 return(NOEXCEPTION);
104 }
105
106
107
108 if (Sgl_isone_signaling(opnd2)) {
109
110 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
111
112 Set_invalidflag();
113 Sgl_set_quiet(opnd2);
114 }
115
116
117
118 *dstptr = opnd2;
119 return(NOEXCEPTION);
120 }
121
122
123
124 if (Sgl_iszero_exponentmantissa(opnd2)) {
125
126 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
127 Set_invalidflag();
128 Sgl_makequietnan(result);
129 *dstptr = result;
130 return(NOEXCEPTION);
131 }
132
133
134
135
136 result = opnd1;
137
138
139
140
141 if (opnd1_exponent == 0) {
142
143 if (Sgl_iszero_mantissa(opnd1)) {
144 *dstptr = opnd1;
145 return(NOEXCEPTION);
146 }
147
148 opnd1_exponent = 1;
149 Sgl_normalize(opnd1,opnd1_exponent);
150 }
151 else {
152 Sgl_clear_signexponent_set_hidden(opnd1);
153 }
154 if (opnd2_exponent == 0) {
155
156 opnd2_exponent = 1;
157 Sgl_normalize(opnd2,opnd2_exponent);
158 }
159 else {
160 Sgl_clear_signexponent_set_hidden(opnd2);
161 }
162
163
164 dest_exponent = opnd2_exponent - 1;
165 stepcount = opnd1_exponent - opnd2_exponent;
166
167
168
169
170 if (stepcount < 0) {
171
172
173
174
175
176
177 if (stepcount == -1 && Sgl_isgreaterthan(opnd1,opnd2)) {
178 Sgl_all(result) = ~Sgl_all(result);
179
180 Sgl_leftshiftby1(opnd2);
181 Sgl_subtract(opnd2,opnd1,opnd2);
182
183 while (Sgl_iszero_hidden(opnd2)) {
184 Sgl_leftshiftby1(opnd2);
185 dest_exponent--;
186 }
187 Sgl_set_exponentmantissa(result,opnd2);
188 goto testforunderflow;
189 }
190
191
192
193
194
195
196 Sgl_set_exponentmantissa(result,opnd1);
197 dest_exponent = opnd1_exponent;
198 goto testforunderflow;
199 }
200
201
202
203
204
205
206 while (stepcount-- > 0 && Sgl_all(opnd1)) {
207 if (Sgl_isnotlessthan(opnd1,opnd2))
208 Sgl_subtract(opnd1,opnd2,opnd1);
209 Sgl_leftshiftby1(opnd1);
210 }
211
212
213
214
215 if (Sgl_isnotlessthan(opnd1,opnd2)) {
216 Sgl_subtract(opnd1,opnd2,opnd1);
217 roundup = TRUE;
218 }
219 if (stepcount > 0 || Sgl_iszero(opnd1)) {
220
221 Sgl_setzero_exponentmantissa(result);
222 *dstptr = result;
223 return(NOEXCEPTION);
224 }
225
226
227
228
229
230
231
232 Sgl_leftshiftby1(opnd1);
233 if (Sgl_isgreaterthan(opnd1,opnd2)) {
234 Sgl_invert_sign(result);
235 Sgl_subtract((opnd2<<1),opnd1,opnd1);
236 }
237
238 else if (Sgl_isequal(opnd1,opnd2) && roundup) {
239 Sgl_invert_sign(result);
240 }
241
242
243 while (Sgl_iszero_hidden(opnd1)) {
244 dest_exponent--;
245 Sgl_leftshiftby1(opnd1);
246 }
247 Sgl_set_exponentmantissa(result,opnd1);
248
249
250
251
252 testforunderflow:
253 if (dest_exponent <= 0) {
254
255 if (Is_underflowtrap_enabled()) {
256
257
258
259 Sgl_setwrapped_exponent(result,dest_exponent,unfl);
260 *dstptr = result;
261
262 return(UNDERFLOWEXCEPTION);
263 }
264
265
266
267 if (dest_exponent >= (1 - SGL_P)) {
268 Sgl_rightshift_exponentmantissa(result,1-dest_exponent);
269 }
270 else {
271 Sgl_setzero_exponentmantissa(result);
272 }
273 }
274 else Sgl_set_exponent(result,dest_exponent);
275 *dstptr = result;
276 return(NOEXCEPTION);
277 }