Back to index

glibc  2.9
s_scalbln.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 "math_private.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 __scalbln (double x, long int n)
00039 #else
00040        double __scalbln (x,n)
00041        double x; long 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            }
00053         if (k==0x7ff) return x+x;         /* NaN or Inf */
00054         k = k+n;
00055         if (n> 50000 || k >  0x7fe)
00056          return huge*__copysign(huge,x); /* overflow  */
00057        if (n< -50000) return tiny*__copysign(tiny,x); /*underflow*/
00058         if (k > 0)                        /* normal result */
00059            {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
00060         if (k <= -54)
00061          return tiny*__copysign(tiny,x);  /*underflow*/
00062         k += 54;                          /* subnormal result */
00063        SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
00064         return x*twom54;
00065 }
00066 weak_alias (__scalbln, scalbln)
00067 #ifdef NO_LONG_DOUBLE
00068 strong_alias (__scalbln, __scalblnl)
00069 weak_alias (__scalbln, scalblnl)
00070 #endif