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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [mathfp/] [s_frexp.c] - Blame information for rev 1777

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

Line No. Rev Author Line
1 56 joel
 
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 non zero, 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
@ifinfo
37
<[m]> and <[p]> are calculated so that
38
<[val]> is <[m]> times <<2>> to the power <[p]>.
39
@end ifinfo
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
  EXTRACT_WORDS (hd, ld, d);
86
 
87
  /* Get the exponent. */
88
  *exp = ((hd & 0x7ff00000) >> 20) - 1022;
89
 
90
  /* Get the mantissa. */
91
  lf = ld;
92
  hf = hd & 0x800fffff;
93
  hf |= 0x3fe00000;
94
 
95
  INSERT_WORDS (f, hf, lf);
96
 
97
  /* Check for special values. */
98
  switch (numtest (f))
99
    {
100
      case NAN:
101
      case INF:
102
        errno = EDOM;
103
        *exp = 0;
104
        return (f);
105
    }
106
 
107
  return (f);
108
}
109
 
110
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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