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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [mathfp/] [sf_ldexp.c] - Blame information for rev 1782

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

Line No. Rev Author Line
1 56 joel
 
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
float
24
_DEFUN (ldexpf, (float, int),
25
        float d _AND
26
        int e)
27
{
28
  int exp;
29
  __int32_t wd;
30
 
31
  GET_FLOAT_WORD (wd, d);
32
 
33
  /* Check for special values and then scale d by e. */
34
  switch (numtestf (wd))
35
    {
36
      case NAN:
37
        errno = EDOM;
38
        break;
39
 
40
      case INF:
41
        errno = ERANGE;
42
        break;
43
 
44
      case 0:
45
        break;
46
 
47
      default:
48
        exp = (wd & 0x7f800000) >> 23;
49
        exp += e;
50
 
51
        if (exp > (FLT_MAX_EXP + 127))
52
         {
53
           errno = ERANGE;
54
           d = z_infinity_f.f;
55
         }
56
        else if (exp < FLT_MIN_EXP - 127)
57
         {
58
           errno = ERANGE;
59
           d = -z_infinity_f.f;
60
         }
61
        else
62
         {
63
           wd &= 0x807fffff;
64
           wd |= exp << 23;
65
           SET_FLOAT_WORD (d, wd);
66
         }
67
    }
68
 
69
    return (d);
70
}
71
 
72
#ifdef _DOUBLE_IS_32BITS
73
 
74
double ldexp (double x, int e)
75
{
76
  return (double) ldexpf ((float) x, e);
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.