source: trunk/sys/libm/s_frexp.c @ 291

Last change on this file since 291 was 1, checked in by alain, 8 years ago

First import

File size: 1.4 KB
RevLine 
[1]1
2/* @(#)s_frexp.c 5.1 93/09/24 */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14/*
15 * for non-zero x
16 *      x = frexp(arg,&exp);
17 * return a double fp quantity x such that 0.5 <= |x| <1.0
18 * and the corresponding binary exponent "exp". That is
19 *      arg = x*2^exp.
20 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
21 * with *exp=0.
22 */
23
24#include <libm/fdlibm.h>
25
26#ifdef __STDC__
27static const double
28#else
29static double
30#endif
31one   =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
32two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
33
34#ifdef __STDC__
35        double frexp(double x, int *eptr)
36#else
37        double frexp(x, eptr)
38        double x; int *eptr;
39#endif
40{
41        int n0, hx, ix, lx;
42        n0 = 1^((*(int*)&one)>>29);
43        hx = *(n0+(int*)&x);
44        ix = 0x7fffffff&hx;
45        lx = *(1-n0+(int*)&x);
46        *eptr = 0;
47        if(ix>=0x7ff00000||((ix|lx)==0)) return x;      /* 0,inf,nan */
48        if (ix<0x00100000) {            /* subnormal */
49            x *= two54;
50            hx = *(n0+(int*)&x);
51            ix = hx&0x7fffffff;
52            *eptr = -54;
53        }
54        *eptr += (ix>>20)-1022;
55        hx = (hx&0x800fffff)|0x3fe00000;
56        *(int*)&x = hx;
57        return x;
58}
Note: See TracBrowser for help on using the repository browser.