Back to index

glibc  2.9
s_frexp.c
Go to the documentation of this file.
00001 /* @(#)s_frexp.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_frexp.c,v 1.9 1995/05/10 20:47:24 jtc Exp $";
00015 #endif
00016 
00017 /*
00018  * for non-zero x
00019  *     x = frexp(arg,&exp);
00020  * return a double fp quantity x such that 0.5 <= |x| <1.0
00021  * and the corresponding binary exponent "exp". That is
00022  *     arg = x*2^exp.
00023  * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
00024  * with *exp=0.
00025  */
00026 
00027 #include "math.h"
00028 #include "math_private.h"
00029 
00030 #ifdef __STDC__
00031 static const double
00032 #else
00033 static double
00034 #endif
00035 two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
00036 
00037 #ifdef __STDC__
00038        double __frexp(double x, int *eptr)
00039 #else
00040        double __frexp(x, eptr)
00041        double x; int *eptr;
00042 #endif
00043 {
00044        int32_t hx, ix, lx;
00045        EXTRACT_WORDS(hx,lx,x);
00046        ix = 0x7fffffff&hx;
00047        *eptr = 0;
00048        if(ix>=0x7ff00000||((ix|lx)==0)) return x;       /* 0,inf,nan */
00049        if (ix<0x00100000) {        /* subnormal */
00050            x *= two54;
00051            GET_HIGH_WORD(hx,x);
00052            ix = hx&0x7fffffff;
00053            *eptr = -54;
00054        }
00055        *eptr += (ix>>20)-1022;
00056        hx = (hx&0x800fffff)|0x3fe00000;
00057        SET_HIGH_WORD(x,hx);
00058        return x;
00059 }
00060 weak_alias (__frexp, frexp)
00061 #ifdef NO_LONG_DOUBLE
00062 strong_alias (__frexp, __frexpl)
00063 weak_alias (__frexp, frexpl)
00064 #endif