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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libm/] [mathfp/] [sf_ldexp.c] - Blame information for rev 258

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

Line No. Rev Author Line
1 207 jeremybenn
 
2
/* @(#)z_ldexpf.c 1.0 98/08/13 */
3
/******************************************************************
4
 * ldexp
5
 *
6
 * Input:
7
 *   d - a floating point value
8
 *   e - an exponent value
9
 *
10
 * Output:
11
 *   A floating point value f such that f = d * 2 ^ e.
12
 *
13
 * Description:
14
 *   This function creates a floating point number f such that
15
 *   f = d * 2 ^ e.
16
 *
17
 *****************************************************************/
18
 
19
#include <float.h>
20
#include "fdlibm.h"
21
#include "zmath.h"
22
 
23
#define FLOAT_EXP_OFFS 127
24
 
25
float
26
_DEFUN (ldexpf, (float, int),
27
        float d _AND
28
        int e)
29
{
30
  int exp;
31
  __int32_t wd;
32
 
33
  GET_FLOAT_WORD (wd, d);
34
 
35
  /* Check for special values and then scale d by e. */
36
  switch (numtestf (wd))
37
    {
38
      case NAN:
39
        errno = EDOM;
40
        break;
41
 
42
      case INF:
43
        errno = ERANGE;
44
        break;
45
 
46
      case 0:
47
        break;
48
 
49
      default:
50
        exp = (wd & 0x7f800000) >> 23;
51
        exp += e;
52
 
53
        if (exp > FLT_MAX_EXP + FLOAT_EXP_OFFS)
54
         {
55
           errno = ERANGE;
56
           d = z_infinity_f.f;
57
         }
58
        else if (exp < FLT_MIN_EXP + FLOAT_EXP_OFFS)
59
         {
60
           errno = ERANGE;
61
           d = -z_infinity_f.f;
62
         }
63
        else
64
         {
65
           wd &= 0x807fffff;
66
           wd |= exp << 23;
67
           SET_FLOAT_WORD (d, wd);
68
         }
69
    }
70
 
71
    return (d);
72
}
73
 
74
#ifdef _DOUBLE_IS_32BITS
75
 
76
double ldexp (double x, int e)
77
{
78
  return (double) ldexpf ((float) x, e);
79
}
80
 
81
#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.