Back to index

glibc  2.9
s_frexpl.c
Go to the documentation of this file.
00001 /* s_frexpl.c -- long double version of s_frexp.c.
00002  * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: $";
00018 #endif
00019 
00020 /*
00021  * for non-zero x
00022  *     x = frexpl(arg,&exp);
00023  * return a long double fp quantity x such that 0.5 <= |x| <1.0
00024  * and the corresponding binary exponent "exp". That is
00025  *     arg = x*2^exp.
00026  * If arg is inf, 0.0, or NaN, then frexpl(arg,&exp) returns arg
00027  * with *exp=0.
00028  */
00029 
00030 #include "math.h"
00031 #include "math_private.h"
00032 
00033 #ifdef __STDC__
00034 static const long double
00035 #else
00036 static long double
00037 #endif
00038 two114 = 2.0769187434139310514121985316880384E+34L; /* 0x4071000000000000, 0 */
00039 
00040 #ifdef __STDC__
00041        long double __frexpl(long double x, int *eptr)
00042 #else
00043        long double __frexpl(x, eptr)
00044        long double x; int *eptr;
00045 #endif
00046 {
00047        u_int64_t hx, lx, ix;
00048        GET_LDOUBLE_WORDS64(hx,lx,x);
00049        ix = 0x7fffffffffffffffULL&hx;
00050        *eptr = 0;
00051        if(ix>=0x7fff000000000000ULL||((ix|lx)==0)) return x;   /* 0,inf,nan */
00052        if (ix<0x0001000000000000ULL) {           /* subnormal */
00053            x *= two114;
00054            GET_LDOUBLE_MSW64(hx,x);
00055            ix = hx&0x7fffffffffffffffULL;
00056            *eptr = -114;
00057        }
00058        *eptr += (ix>>48)-16382;
00059        hx = (hx&0x8000ffffffffffffULL) | 0x3ffe000000000000ULL;
00060        SET_LDOUBLE_MSW64(x,hx);
00061        return x;
00062 }
00063 weak_alias (__frexpl, frexpl)