source: trunk/libs/newlib/src/newlib/libm/mathfp/s_frexp.c @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

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