Rev | Line | |
---|
[9] | 1 | /*
|
---|
| 2 | libc/ieee_float/modf.c
|
---|
| 3 |
|
---|
| 4 | Created: Oct 14, 1993 by Philip Homburg <philip@cs.vu.nl>
|
---|
| 5 |
|
---|
| 6 | Implementation of modf that directly manipulates the exponent bits in an
|
---|
| 7 | ieee float
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #include <sys/types.h>
|
---|
| 11 | #include <math.h>
|
---|
| 12 |
|
---|
| 13 | #include "ieee_float.h"
|
---|
| 14 |
|
---|
| 15 | double modf(value, iptr)
|
---|
| 16 | double value;
|
---|
| 17 | double *iptr;
|
---|
| 18 | {
|
---|
| 19 | struct f64 *f64p;
|
---|
| 20 | double tmp;
|
---|
| 21 | int exp;
|
---|
| 22 | int mask_bits;
|
---|
| 23 | u32_t mant;
|
---|
| 24 |
|
---|
| 25 | f64p= (struct f64 *)&value;
|
---|
| 26 |
|
---|
| 27 | exp= F64_GET_EXP(f64p);
|
---|
| 28 | exp -= F64_EXP_BIAS;
|
---|
| 29 | if (exp < 0)
|
---|
| 30 | {
|
---|
| 31 | *iptr= 0;
|
---|
| 32 | return value;
|
---|
| 33 | }
|
---|
| 34 | mask_bits= 52-exp;
|
---|
| 35 | if (mask_bits <= 0)
|
---|
| 36 | {
|
---|
| 37 | *iptr= value;
|
---|
| 38 | return 0;
|
---|
| 39 | }
|
---|
| 40 | tmp= value;
|
---|
| 41 | if (mask_bits >= 32)
|
---|
| 42 | {
|
---|
| 43 | F64_SET_MANT_LOW(f64p, 0);
|
---|
| 44 | mask_bits -= 32;
|
---|
| 45 | mant= F64_GET_MANT_HIGH(f64p);
|
---|
| 46 | mant &= ~((1 << mask_bits)-1);
|
---|
| 47 | F64_SET_MANT_HIGH(f64p, mant);
|
---|
| 48 | }
|
---|
| 49 | else
|
---|
| 50 | {
|
---|
| 51 | mant= F64_GET_MANT_LOW(f64p);
|
---|
| 52 | mant &= ~((1 << mask_bits)-1);
|
---|
| 53 | F64_SET_MANT_LOW(f64p, mant);
|
---|
| 54 | }
|
---|
| 55 | *iptr= value;
|
---|
| 56 | return tmp-value;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | /*
|
---|
| 60 | * $PchId: modf.c,v 1.3 1996/02/22 21:01:39 philip Exp $
|
---|
| 61 | */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.