1
/* @(#)s_scalbn.c 5.1 93/09/24 */
2
/* @(#)fdlibm.h 5.1 93/09/24 */
4
* ====================================================
5
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7
* Developed at SunPro, a Sun Microsystems, Inc. business.
8
* Permission to use, copy, modify, and distribute this
9
* software is freely granted, provided that this notice
11
* ====================================================
14
#include <sys/cdefs.h>
16
#include <sys/types.h>
20
/* Bit fiddling routines copied from msun/src/math_private.h,v 1.15 */
22
#if BYTE_ORDER == BIG_ENDIAN
32
} ieee_double_shape_type;
36
#if BYTE_ORDER == LITTLE_ENDIAN
46
} ieee_double_shape_type;
50
/* Get two 32 bit ints from a double. */
52
#define EXTRACT_WORDS(ix0,ix1,d) \
54
ieee_double_shape_type ew_u; \
56
(ix0) = ew_u.parts.msw; \
57
(ix1) = ew_u.parts.lsw; \
60
/* Get the more significant 32 bit int from a double. */
62
#define GET_HIGH_WORD(i,d) \
64
ieee_double_shape_type gh_u; \
66
(i) = gh_u.parts.msw; \
69
/* Set the more significant 32 bits of a double from an int. */
71
#define SET_HIGH_WORD(d,v) \
73
ieee_double_shape_type sh_u; \
75
sh_u.parts.msw = (v); \
81
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
82
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
87
_copysign(double x, double y)
92
SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
97
ldexp(double x, int n)
100
EXTRACT_WORDS(hx,lx,x);
101
k = (hx&0x7ff00000)>>20; /* extract exponent */
102
if (k==0) { /* 0 or subnormal x */
103
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
106
k = ((hx&0x7ff00000)>>20) - 54;
107
if (n< -50000) return tiny*x; /*underflow*/
109
if (k==0x7ff) return x+x; /* NaN or Inf */
111
if (k > 0x7fe) return huge*_copysign(huge,x); /* overflow */
112
if (k > 0) /* normal result */
113
{SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
115
if (n > 50000) /* in case integer overflow in n+k */
116
return huge*_copysign(huge,x); /*overflow*/
117
else return tiny*_copysign(tiny,x); /*underflow*/
119
k += 54; /* subnormal result */
120
SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));