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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [mathfp/] [s_ldexp.c] - Blame information for rev 148

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

Line No. Rev Author Line
1 148 jeremybenn
 
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
@ifnottex
32
<[val]> times 2 to the power <[exp]>.
33
@end ifnottex
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
#define DOUBLE_EXP_OFFS 1023
75
 
76
double
77
_DEFUN (ldexp, (double, int),
78
        double d _AND
79
        int e)
80
{
81
  int exp;
82
  __uint32_t hd;
83
 
84
  GET_HIGH_WORD (hd, d);
85
 
86
  /* Check for special values and then scale d by e. */
87
  switch (numtest (d))
88
    {
89
      case NAN:
90
        errno = EDOM;
91
        break;
92
 
93
      case INF:
94
        errno = ERANGE;
95
        break;
96
 
97
      case 0:
98
        break;
99
 
100
      default:
101
        exp = (hd & 0x7ff00000) >> 20;
102
        exp += e;
103
 
104
        if (exp > DBL_MAX_EXP + DOUBLE_EXP_OFFS)
105
         {
106
           errno = ERANGE;
107
           d = z_infinity.d;
108
         }
109
        else if (exp < DBL_MIN_EXP + DOUBLE_EXP_OFFS)
110
         {
111
           errno = ERANGE;
112
           d = -z_infinity.d;
113
         }
114
        else
115
         {
116
           hd &= 0x800fffff;
117
           hd |= exp << 20;
118
           SET_HIGH_WORD (d, hd);
119
         }
120
    }
121
 
122
    return (d);
123
}
124
 
125
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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