base/math/s_scalbn.c

Go to the documentation of this file.
00001 /* @(#)s_scalbn.c 5.1 93/09/24 */ 00002 /* 00003 * ==================================================== 00004 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 00005 * 00006 * Developed at SunPro, a Sun Microsystems, Inc. business. 00007 * Permission to use, copy, modify, and distribute this 00008 * software is freely granted, provided that this notice 00009 * is preserved. 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 * scalbn (double x, int n) 00019 * scalbn(x,n) returns x* 2**n computed by exponent 00020 * manipulation rather than by actually performing an 00021 * exponentiation or a multiplication. 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, /* 0x43500000, 0x00000000 */ 00033 twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ 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; /* extract exponent */ 00047 if (k==0) { /* 0 or subnormal x */ 00048 if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ 00049 x *= two54; 00050 GET_HIGH_WORD(hx,x); 00051 k = ((hx&0x7ff00000)>>20) - 54; 00052 if (n< -50000) return tiny*x; /*underflow*/ 00053 } 00054 if (k==0x7ff) return x+x; /* NaN or Inf */ 00055 k = k+n; 00056 if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */ 00057 if (k > 0) /* normal result */ 00058 {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} 00059 if (k <= -54) { 00060 if (n > 50000) /* in case integer overflow in n+k */ 00061 return huge*copysign(huge,x); /*overflow*/ 00062 else return tiny*copysign(tiny,x); /*underflow*/ 00063 } 00064 k += 54; /* subnormal result */ 00065 SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); 00066 return x*twom54; 00067 }

Generated on Thu Nov 20 11:49:52 2008 for RTAI API by doxygen 1.3.8