Back to index

glibc  2.9
s_scalblnl.c
Go to the documentation of this file.
00001 /* s_scalblnl.c -- long double version of s_scalbn.c.
00002  * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
00003  */
00004    
00005 /* @(#)s_scalbn.c 5.1 93/09/24 */
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  * scalblnl (long double x, long int n)
00023  * scalblnl(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 two114 = 2.0769187434139310514121985316880384E+34L, /* 0x4071000000000000, 0 */
00037 twom114 = 4.8148248609680896326399448564623183E-35L, /* 0x3F8D000000000000, 0 */
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        int64_t k,hx,lx;
00049        GET_LDOUBLE_WORDS64(hx,lx,x);
00050         k = (hx>>48)&0x7fff;              /* extract exponent */
00051         if (k==0) {                       /* 0 or subnormal x */
00052             if ((lx|(hx&0x7fffffffffffffffULL))==0) return x; /* +-0 */
00053            x *= two114;
00054            GET_LDOUBLE_MSW64(hx,x);
00055            k = ((hx>>48)&0x7fff) - 114;
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) return tiny*__copysignl(tiny,x); /*underflow*/
00062         if (k > 0)                        /* normal result */
00063            {SET_LDOUBLE_MSW64(x,(hx&0x8000ffffffffffffULL)|(k<<48)); return x;}
00064         if (k <= -114)
00065          return tiny*__copysignl(tiny,x);        /*underflow*/
00066         k += 114;                         /* subnormal result */
00067        SET_LDOUBLE_MSW64(x,(hx&0x8000ffffffffffffULL)|(k<<48));
00068         return x*twom114;
00069 }
00070 weak_alias (__scalblnl, scalblnl)