Back to index

glibc  2.9
s_scalblnl.c
Go to the documentation of this file.
00001 /* s_scalbnl.c -- long double version of s_scalbn.c.
00002  * Conversion to long double by Ulrich Drepper,
00003  * Cygnus Support, drepper@cygnus.com.
00004  */
00005 
00006 /*
00007  * ====================================================
00008  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00009  *
00010  * Developed at SunPro, a Sun Microsystems, Inc. business.
00011  * Permission to use, copy, modify, and distribute this
00012  * software is freely granted, provided that this notice
00013  * is preserved.
00014  * ====================================================
00015  */
00016 
00017 #if defined(LIBM_SCCS) && !defined(lint)
00018 static char rcsid[] = "$NetBSD: $";
00019 #endif
00020 
00021 /*
00022  * scalbnl (long double x, int n)
00023  * scalbnl(x,n) returns x* 2**n  computed by  exponent
00024  * manipulation rather than by actually performing an
00025  * exponentiation or a multiplication.
00026  */
00027 
00028 #include "math.h"
00029 #include "math_private.h"
00030 
00031 #ifdef __STDC__
00032 static const long double
00033 #else
00034 static long double
00035 #endif
00036 two63   =  4.50359962737049600000e+15,
00037 twom63  =  1.08420217248550443400e-19,
00038 huge   = 1.0e+4900L,
00039 tiny   = 1.0e-4900L;
00040 
00041 #ifdef __STDC__
00042        long double __scalblnl (long double x, long int n)
00043 #else
00044        long double __scalblnl (x,n)
00045        long double x; long int n;
00046 #endif
00047 {
00048        int32_t k,es,hx,lx;
00049        GET_LDOUBLE_WORDS(es,hx,lx,x);
00050         k = es&0x7fff;                           /* extract exponent */
00051         if (k==0) {                       /* 0 or subnormal x */
00052             if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
00053            x *= two63;
00054            GET_LDOUBLE_EXP(es,x);
00055            k = (hx&0x7fff) - 63;
00056            }
00057         if (k==0x7fff) return x+x;        /* NaN or Inf */
00058         k = k+n;
00059         if (n> 50000 || k > 0x7ffe)
00060          return huge*__copysignl(huge,x); /* overflow  */
00061        if (n< -50000)
00062          return tiny*__copysignl(tiny,x);
00063         if (k > 0)                        /* normal result */
00064            {SET_LDOUBLE_EXP(x,(es&0x8000)|k); return x;}
00065         if (k <= -63)
00066            return tiny*__copysignl(tiny,x);      /*underflow*/
00067         k += 63;                          /* subnormal result */
00068        SET_LDOUBLE_EXP(x,(es&0x8000)|k);
00069         return x*twom63;
00070 }
00071 weak_alias (__scalblnl, scalblnl)