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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [mathfp/] [s_ldexp.c] - Blame information for rev 1775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 joel
 
2
/* @(#)z_ldexp.c 1.0 98/08/13 */
3
 
4
/*
5
FUNCTION
6
       <<ldexp>>, <<ldexpf>>---load exponent
7
 
8
INDEX
9
        ldexp
10
INDEX
11
        ldexpf
12
 
13
ANSI_SYNOPSIS
14
       #include <math.h>
15
       double ldexp(double <[val]>, int <[exp]>);
16
       float ldexpf(float <[val]>, int <[exp]>);
17
 
18
TRAD_SYNOPSIS
19
       #include <math.h>
20
 
21
       double ldexp(<[val]>, <[exp]>)
22
              double <[val]>;
23
              int <[exp]>;
24
 
25
       float ldexpf(<[val]>, <[exp]>)
26
              float <[val]>;
27
              int <[exp]>;
28
 
29
DESCRIPTION
30
<<ldexp>> calculates the value
31
@ifinfo
32
<[val]> times 2 to the power <[exp]>.
33
@end ifinfo
34
@tex
35
$val\times 2^{exp}$.
36
@end tex
37
<<ldexpf>> is identical, save that it takes and returns <<float>>
38
rather than <<double>> values.
39
 
40
RETURNS
41
<<ldexp>> returns the calculated value.
42
 
43
Underflow and overflow both set <<errno>> to <<ERANGE>>.
44
On underflow, <<ldexp>> and <<ldexpf>> return 0.0.
45
On overflow, <<ldexp>> returns plus or minus <<HUGE_VAL>>.
46
 
47
PORTABILITY
48
<<ldexp>> is ANSI, <<ldexpf>> is an extension.
49
 
50
*/
51
 
52
/******************************************************************
53
 * ldexp
54
 *
55
 * Input:
56
 *   d - a floating point value
57
 *   e - an exponent value
58
 *
59
 * Output:
60
 *   A floating point value f such that f = d * 2 ^ e.
61
 *
62
 * Description:
63
 *   This function creates a floating point number f such that
64
 *   f = d * 2 ^ e.
65
 *
66
 *****************************************************************/
67
 
68
#include <float.h>
69
#include "fdlibm.h"
70
#include "zmath.h"
71
 
72
#ifndef _DOUBLE_IS_32BITS
73
 
74
double
75
_DEFUN (ldexp, (double, int),
76
        double d _AND
77
        int e)
78
{
79
  int exp;
80
  __uint32_t hd;
81
 
82
  GET_HIGH_WORD (hd, d);
83
 
84
  /* Check for special values and then scale d by e. */
85
  switch (numtest (d))
86
    {
87
      case NAN:
88
        errno = EDOM;
89
        break;
90
 
91
      case INF:
92
        errno = ERANGE;
93
        break;
94
 
95
      case 0:
96
        break;
97
 
98
      default:
99
        exp = (hd & 0x7ff00000) >> 20;
100
        exp += e;
101
 
102
        if (exp > (DBL_MAX_EXP + 1023))
103
         {
104
           errno = ERANGE;
105
           d = z_infinity.d;
106
         }
107
        else if (exp < DBL_MIN_EXP)
108
         {
109
           errno = ERANGE;
110
           d = -z_infinity.d;
111
         }
112
        else
113
         {
114
           hd &= 0x800fffff;
115
           hd |= exp << 20;
116
           SET_HIGH_WORD (d, hd);
117
         }
118
    }
119
 
120
    return (d);
121
}
122
 
123
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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