Rev 828 | Rev 835 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 828 | Rev 829 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | #include<sftypes.h> |
29 | #include<sftypes.h> |
30 | #include<add.h> |
30 | #include<add.h> |
31 | #include<div.h> |
31 | #include<div.h> |
32 | #include<comparison.h> |
32 | #include<comparison.h> |
33 | #include<mul.h> |
33 | #include<mul.h> |
- | 34 | #include<common.h> |
|
- | 35 | ||
34 | 36 | ||
35 | float32 divFloat32(float32 a, float32 b) |
37 | float32 divFloat32(float32 a, float32 b) |
36 | { |
38 | { |
37 | float32 result; |
39 | float32 result; |
38 | __s32 aexp, bexp, cexp; |
40 | __s32 aexp, bexp, cexp; |
Line 304... | Line 306... | ||
304 | remhi += ( remlo < bfrac ); |
306 | remhi += ( remlo < bfrac ); |
305 | } |
307 | } |
306 | cfrac |= ( remlo != 0 ); |
308 | cfrac |= ( remlo != 0 ); |
307 | } |
309 | } |
308 | 310 | ||
309 | /* pack and round */ |
311 | /* round and shift */ |
310 | - | ||
311 | /* find first nonzero digit and shift result and detect possibly underflow */ |
- | |
312 | while ((cexp > 0) && (cfrac) && (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1 ) )))) { |
- | |
313 | cexp--; |
- | |
314 | cfrac <<= 1; |
- | |
315 | /* TODO: fix underflow */ |
- | |
316 | }; |
- | |
317 | - | ||
318 | - | ||
319 | cfrac >>= 1; |
- | |
320 | ++cexp; |
- | |
321 | cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); |
- | |
322 | - | ||
323 | if (cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1 ))) { |
- | |
324 | ++cexp; |
- | |
325 | cfrac >>= 1; |
- | |
326 | } |
- | |
327 | - | ||
328 | /* check overflow */ |
- | |
329 | if (cexp >= FLOAT64_MAX_EXPONENT ) { |
- | |
330 | /* FIXME: overflow, return infinity */ |
- | |
331 | result.parts.exp = FLOAT64_MAX_EXPONENT; |
312 | result = finishFloat64(cexp, cfrac, result.parts.sign); |
332 | result.parts.fraction = 0; |
- | |
333 | return result; |
313 | return result; |
334 | } |
- | |
335 | 314 | ||
336 | if (cexp < 0) { |
- | |
337 | /* FIXME: underflow */ |
- | |
338 | result.parts.exp = 0; |
- | |
339 | if ((cexp + FLOAT64_FRACTION_SIZE) < 0) { |
- | |
340 | result.parts.fraction = 0; |
- | |
341 | return result; |
- | |
342 | } |
- | |
343 | cfrac >>= 1; |
- | |
344 | while (cexp < 0) { |
- | |
345 | cexp ++; |
- | |
346 | cfrac >>= 1; |
- | |
347 | } |
- | |
348 | return result; |
- | |
349 | - | ||
350 | } else { |
- | |
351 | cexp ++; /*normalized*/ |
- | |
352 | result.parts.exp = (__u32)cexp; |
- | |
353 | } |
- | |
354 | - | ||
355 | result.parts.fraction = ((cfrac >>(64 - FLOAT64_FRACTION_SIZE - 2 ) ) & (~FLOAT64_HIDDEN_BIT_MASK)); |
- | |
356 | - | ||
357 | return result; |
- | |
358 | } |
315 | } |
359 | 316 | ||
360 | __u64 divFloat64estim(__u64 a, __u64 b) |
317 | __u64 divFloat64estim(__u64 a, __u64 b) |
361 | { |
318 | { |
362 | __u64 bhi; |
319 | __u64 bhi; |