2 libc/ieee_float/ldexp.c
4 Created: Oct 14, 1993 by Philip Homburg <philip@cs.vu.nl>
6 Implementation of ldexp that directly manipulates the exponent bits in an
10 #include <sys/types.h>
14 #include "ieee_float.h"
16 double ldexp(value
, exp
)
24 f64p
= (struct f64
*)&value
;
27 oldexp
= F64_GET_EXP(f64p
);
28 if (oldexp
== F64_EXP_MAX
)
29 { /* Either infinity or Nan */
34 /* Either 0 or denormal */
35 if (F64_GET_MANT_LOW(f64p
) == 0 &&
36 F64_GET_MANT_HIGH(f64p
) == 0)
42 /* If exp is too large (> 2*F64_EXP_MAX) or too small
43 * (< -2*F64_EXP_MAX) return HUGE_VAL or 0. This prevents overflows
44 * in exp if exp is really weird
46 if (exp
>= 2*F64_EXP_MAX
)
51 if (exp
<= -2*F64_EXP_MAX
)
57 /* Normalize a denormal */
60 /* Multiply by 2^64 */
61 factor
= 65536.0; /* 2^16 */
62 factor
*= factor
; /* 2^32 */
63 factor
*= factor
; /* 2^64 */
66 oldexp
= F64_GET_EXP(f64p
);
70 if (exp
>= F64_EXP_MAX
)
78 F64_SET_EXP(f64p
, exp
);
81 /* Denormal, or underflow. */
83 F64_SET_EXP(f64p
, exp
);
85 factor
= 65536.0; /* 2^16 */
86 factor
*= factor
; /* 2^32 */
87 factor
*= factor
; /* 2^64 */
98 * $PchId: ldexp.c,v 1.3 1996/02/22 21:01:39 philip Exp $