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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 148 jeremybenn
 
2
/* @(#)z_frexp.c 1.0 98/08/13 */
3
 
4
/*
5
FUNCTION
6
       <<frexp>>, <<frexpf>>---split floating-point number
7
INDEX
8
        frexp
9
INDEX
10
        frexpf
11
 
12
ANSI_SYNOPSIS
13
        #include <math.h>
14
        double frexp(double <[val]>, int *<[exp]>);
15
        float frexpf(float <[val]>, int *<[exp]>);
16
 
17
TRAD_SYNOPSIS
18
        #include <math.h>
19
        double frexp(<[val]>, <[exp]>)
20
        double <[val]>;
21
        int *<[exp]>;
22
 
23
        float frexpf(<[val]>, <[exp]>)
24
        float <[val]>;
25
        int *<[exp]>;
26
 
27
 
28
DESCRIPTION
29
        All nonzero, normal numbers can be described as <[m]> * 2**<[p]>.
30
        <<frexp>> represents the double <[val]> as a mantissa <[m]>
31
        and a power of two <[p]>. The resulting mantissa will always
32
        be greater than or equal to <<0.5>>, and less than <<1.0>> (as
33
        long as <[val]> is nonzero). The power of two will be stored
34
        in <<*>><[exp]>.
35
 
36
@ifnottex
37
<[m]> and <[p]> are calculated so that
38
<[val]> is <[m]> times <<2>> to the power <[p]>.
39
@end ifnottex
40
@tex
41
<[m]> and <[p]> are calculated so that
42
$ val = m \times 2^p $.
43
@end tex
44
 
45
<<frexpf>> is identical, other than taking and returning
46
floats rather than doubles.
47
 
48
RETURNS
49
<<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
50
or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
51
 
52
PORTABILITY
53
<<frexp>> is ANSI.
54
<<frexpf>> is an extension.
55
 
56
 
57
*/
58
 
59
/*****************************************************************
60
 * frexp
61
 *
62
 * Input:
63
 *   d   - floating point value
64
 *   exp - exponent value
65
 *
66
 * Output:
67
 *   A floating point value in the range [0.5, 1).
68
 *
69
 * Description:
70
 *   This routine breaks a floating point value into a number f and
71
 *   an exponent exp such that d = f * 2 ^ exp.
72
 *
73
 *****************************************************************/
74
 
75
#include "fdlibm.h"
76
#include "zmath.h"
77
 
78
#ifndef _DOUBLE_IS_32BITS
79
 
80
double frexp (double d, int *exp)
81
{
82
  double f;
83
  __uint32_t hd, ld, hf, lf;
84
 
85
  /* Check for special values. */
86
  switch (numtest (d))
87
    {
88
      case NAN:
89
      case INF:
90
        errno = EDOM;
91
      case 0:
92
        *exp = 0;
93
        return (d);
94
    }
95
 
96
  EXTRACT_WORDS (hd, ld, d);
97
 
98
  /* Get the exponent. */
99
  *exp = ((hd & 0x7ff00000) >> 20) - 1022;
100
 
101
  /* Get the mantissa. */
102
  lf = ld;
103
  hf = hd & 0x800fffff;
104
  hf |= 0x3fe00000;
105
 
106
  INSERT_WORDS (f, hf, lf);
107
 
108
  return (f);
109
}
110
 
111
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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