Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sf_frexp.c « mathfp « libm « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f25195c85770c51912b13a60cc07b09e4f8e606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

/* @(#)z_frexpf.c 1.0 98/08/13 */
/******************************************************************
 * frexp
 *
 * Input:
 *   d   - floating point value
 *   exp - exponent value
 *
 * Output:
 *   A floating point value in the range [0.5, 1).
 *
 * Description:
 *   This routine breaks a floating point value into a number f and
 *   an exponent exp such that d = f * 2 ^ exp.
 *
 *****************************************************************/

#include "fdlibm.h"
#include "zmath.h"

float frexpf (float d, int *exp)
{
  float f;
  __int32_t wf, wd;

  /* Check for special values. */
  switch (numtestf (d))
    {
      case NAN:
      case INF:
        errno = EDOM;
      case 0:
        *exp = 0;
        return (d);
    }

  GET_FLOAT_WORD (wd, d);

  /* Get the exponent. */
  *exp = ((wd & 0x7f800000) >> 23) - 126;

  /* Get the mantissa. */ 
  wf = wd & 0x7fffff;  
  wf |= 0x3f000000;

  SET_FLOAT_WORD (f, wf);

  return (f);
}

#ifdef _DOUBLE_IS_32BITS

double frexp (double x, int *exp)
{
  return (double) frexpf ((float) x, exp);
}

#endif /* defined(_DOUBLE_IS_32BITS) */