00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #if defined(LIBM_SCCS) && !defined(lint)
00014 static char rcsid[] = "$NetBSD: s_scalbn.c,v 1.8 1995/05/10 20:48:08 jtc Exp $";
00015 #endif
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "math.h"
00025 #include "mathP.h"
00026
00027 #ifdef __STDC__
00028 static const double
00029 #else
00030 static double
00031 #endif
00032 two54 = 1.80143985094819840000e+16,
00033 twom54 = 5.55111512312578270212e-17,
00034 huge = 1.0e+300,
00035 tiny = 1.0e-300;
00036
00037 #ifdef __STDC__
00038 double scalbn (double x, int n)
00039 #else
00040 double scalbn (x,n)
00041 double x; int n;
00042 #endif
00043 {
00044 int32_t k,hx,lx;
00045 EXTRACT_WORDS(hx,lx,x);
00046 k = (hx&0x7ff00000)>>20;
00047 if (k==0) {
00048 if ((lx|(hx&0x7fffffff))==0) return x;
00049 x *= two54;
00050 GET_HIGH_WORD(hx,x);
00051 k = ((hx&0x7ff00000)>>20) - 54;
00052 if (n< -50000) return tiny*x;
00053 }
00054 if (k==0x7ff) return x+x;
00055 k = k+n;
00056 if (k > 0x7fe) return huge*copysign(huge,x);
00057 if (k > 0)
00058 {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
00059 if (k <= -54) {
00060 if (n > 50000)
00061 return huge*copysign(huge,x);
00062 else return tiny*copysign(tiny,x);
00063 }
00064 k += 54;
00065 SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
00066 return x*twom54;
00067 }