Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* @(#)s_frexp.c 5.1 93/09/24 */
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 */
12
 
13
#ifndef lint
14
static char rcsid[] = "$\Id: s_frexp.c,v 1.3 1995/05/30 05:49:41 rgrimes Exp $";
15
#endif
16
 
17
/*
18
 * for non-zero x
19
 *      x = frexp(arg,&exp);
20
 * return a double fp quantity x such that 0.5 <= |x| <1.0
21
 * and the corresponding binary exponent "exp". That is
22
 *      arg = x*2^exp.
23
 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
24
 * with *exp=0.
25
 */
26
 
27
#include "math.h"
28
#include "math_private.h"
29
 
30
#ifdef __STDC__
31
static const double
32
#else
33
static double
34
#endif
35
two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
36
 
37
#ifdef __STDC__
38
        double frexp(double x, int *eptr)
39
#else
40
        double frexp(x, eptr)
41
        double x; int *eptr;
42
#endif
43
{
44
        int32_t hx, ix, lx;
45
        EXTRACT_WORDS(hx,lx,x);
46
        ix = 0x7fffffff&hx;
47
        *eptr = 0;
48
        if(ix>=0x7ff00000||((ix|lx)==0)) return x;      /* 0,inf,nan */
49
        if (ix<0x00100000) {            /* subnormal */
50
            x *= two54;
51
            GET_HIGH_WORD(hx,x);
52
            ix = hx&0x7fffffff;
53
            *eptr = -54;
54
        }
55
        *eptr += (ix>>20)-1022;
56
        hx = (hx&0x800fffff)|0x3fe00000;
57
        SET_HIGH_WORD(x,hx);
58
        return x;
59
}