Rev 835 | Rev 1657 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 835 | Rev 1031 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | 35 | ||
36 | 36 | ||
37 | float32 divFloat32(float32 a, float32 b) |
37 | float32 divFloat32(float32 a, float32 b) |
38 | { |
38 | { |
39 | float32 result; |
39 | float32 result; |
40 | __s32 aexp, bexp, cexp; |
40 | int32_t aexp, bexp, cexp; |
41 | __u64 afrac, bfrac, cfrac; |
41 | uint64_t afrac, bfrac, cfrac; |
42 | 42 | ||
43 | result.parts.sign = a.parts.sign ^ b.parts.sign; |
43 | result.parts.sign = a.parts.sign ^ b.parts.sign; |
44 | 44 | ||
45 | if (isFloat32NaN(a)) { |
45 | if (isFloat32NaN(a)) { |
46 | if (isFloat32SigNaN(a)) { |
46 | if (isFloat32SigNaN(a)) { |
Line 178... | Line 178... | ||
178 | cexp ++; |
178 | cexp ++; |
179 | cfrac >>= 1; |
179 | cfrac >>= 1; |
180 | } |
180 | } |
181 | 181 | ||
182 | } else { |
182 | } else { |
183 | result.parts.exp = (__u32)cexp; |
183 | result.parts.exp = (uint32_t)cexp; |
184 | } |
184 | } |
185 | 185 | ||
186 | result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); |
186 | result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); |
187 | 187 | ||
188 | return result; |
188 | return result; |
189 | } |
189 | } |
190 | 190 | ||
191 | float64 divFloat64(float64 a, float64 b) |
191 | float64 divFloat64(float64 a, float64 b) |
192 | { |
192 | { |
193 | float64 result; |
193 | float64 result; |
194 | __s64 aexp, bexp, cexp; |
194 | int64_t aexp, bexp, cexp; |
195 | __u64 afrac, bfrac, cfrac; |
195 | uint64_t afrac, bfrac, cfrac; |
196 | __u64 remlo, remhi; |
196 | uint64_t remlo, remhi; |
197 | 197 | ||
198 | result.parts.sign = a.parts.sign ^ b.parts.sign; |
198 | result.parts.sign = a.parts.sign ^ b.parts.sign; |
199 | 199 | ||
200 | if (isFloat64NaN(a)) { |
200 | if (isFloat64NaN(a)) { |
201 | 201 | ||
Line 304... | Line 304... | ||
304 | mul64integers( bfrac, cfrac, &remlo, &remhi); |
304 | mul64integers( bfrac, cfrac, &remlo, &remhi); |
305 | /* (__u128)afrac << 64 - ( ((__u128)remhi<<64) + (__u128)remlo )*/ |
305 | /* (__u128)afrac << 64 - ( ((__u128)remhi<<64) + (__u128)remlo )*/ |
306 | remhi = afrac - remhi - ( remlo > 0); |
306 | remhi = afrac - remhi - ( remlo > 0); |
307 | remlo = - remlo; |
307 | remlo = - remlo; |
308 | 308 | ||
309 | while ((__s64) remhi < 0) { |
309 | while ((int64_t) remhi < 0) { |
310 | cfrac--; |
310 | cfrac--; |
311 | remlo += bfrac; |
311 | remlo += bfrac; |
312 | remhi += ( remlo < bfrac ); |
312 | remhi += ( remlo < bfrac ); |
313 | } |
313 | } |
314 | cfrac |= ( remlo != 0 ); |
314 | cfrac |= ( remlo != 0 ); |
Line 318... | Line 318... | ||
318 | result = finishFloat64(cexp, cfrac, result.parts.sign); |
318 | result = finishFloat64(cexp, cfrac, result.parts.sign); |
319 | return result; |
319 | return result; |
320 | 320 | ||
321 | } |
321 | } |
322 | 322 | ||
323 | __u64 divFloat64estim(__u64 a, __u64 b) |
323 | uint64_t divFloat64estim(uint64_t a, uint64_t b) |
324 | { |
324 | { |
325 | __u64 bhi; |
325 | uint64_t bhi; |
326 | __u64 remhi, remlo; |
326 | uint64_t remhi, remlo; |
327 | __u64 result; |
327 | uint64_t result; |
328 | 328 | ||
329 | if ( b <= a ) { |
329 | if ( b <= a ) { |
330 | return 0xFFFFFFFFFFFFFFFFull; |
330 | return 0xFFFFFFFFFFFFFFFFull; |
331 | } |
331 | } |
332 | 332 | ||
Line 336... | Line 336... | ||
336 | 336 | ||
337 | remhi = a - remhi - (remlo > 0); |
337 | remhi = a - remhi - (remlo > 0); |
338 | remlo = - remlo; |
338 | remlo = - remlo; |
339 | 339 | ||
340 | b <<= 32; |
340 | b <<= 32; |
341 | while ( (__s64) remhi < 0 ) { |
341 | while ( (int64_t) remhi < 0 ) { |
342 | result -= 0x1ll << 32; |
342 | result -= 0x1ll << 32; |
343 | remlo += b; |
343 | remlo += b; |
344 | remhi += bhi + ( remlo < b ); |
344 | remhi += bhi + ( remlo < b ); |
345 | } |
345 | } |
346 | remhi = (remhi << 32) | (remlo >> 32); |
346 | remhi = (remhi << 32) | (remlo >> 32); |