OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [newlib/] [newlib/] [libm/] [common/] [sf_scalbn.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 joel
/* sf_scalbn.c -- float version of s_scalbn.c.
2
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3
 */
4
 
5
/*
6
 * ====================================================
7
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8
 *
9
 * Developed at SunPro, a Sun Microsystems, Inc. business.
10
 * Permission to use, copy, modify, and distribute this
11
 * software is freely granted, provided that this notice
12
 * is preserved.
13
 * ====================================================
14
 */
15
 
16
#include "fdlibm.h"
17
#include <limits.h>
18
 
19
#if INT_MAX > 50000
20
#define OVERFLOW_INT 50000
21
#else
22
#define OVERFLOW_INT 30000
23
#endif
24
 
25
#ifdef __STDC__
26
static const float
27
#else
28
static float
29
#endif
30
two25   =  3.355443200e+07,     /* 0x4c000000 */
31
twom25  =  2.9802322388e-08,    /* 0x33000000 */
32
huge   = 1.0e+30,
33
tiny   = 1.0e-30;
34
 
35
#ifdef __STDC__
36
        float scalbnf (float x, int n)
37
#else
38
        float scalbnf (x,n)
39
        float x; int n;
40
#endif
41
{
42
        __int32_t  k,ix;
43
        GET_FLOAT_WORD(ix,x);
44
        k = (ix&0x7f800000)>>23;                /* extract exponent */
45
        if (k==0) {                              /* 0 or subnormal x */
46
            if ((ix&0x7fffffff)==0) return x; /* +-0 */
47
            x *= two25;
48
            GET_FLOAT_WORD(ix,x);
49
            k = ((ix&0x7f800000)>>23) - 25;
50
            if (n< -50000) return tiny*x;       /*underflow*/
51
            }
52
        if (k==0xff) return x+x;                /* NaN or Inf */
53
        k = k+n;
54
        if (k >  0xfe) return huge*copysignf(huge,x); /* overflow  */
55
        if (k > 0)                               /* normal result */
56
            {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
57
        if (k <= -25)
58
            if (n > OVERFLOW_INT)       /* in case integer overflow in n+k */
59
                return huge*copysignf(huge,x);  /*overflow*/
60
            else return tiny*copysignf(tiny,x); /*underflow*/
61
        k += 25;                                /* subnormal result */
62
        SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
63
        return x*twom25;
64
}
65
 
66
#ifdef _DOUBLE_IS_32BITS
67
 
68
#ifdef __STDC__
69
        double scalbn(double x, int n)
70
#else
71
        double scalbn(x,n)
72
        double x;
73
        int n;
74
#endif
75
{
76
        return (double) scalbnf((float) x, n);
77
}
78
 
79
#endif /* defined(_DOUBLE_IS_32BITS) */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.