2 (C) Copyright IBM Corp. 2009
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of IBM nor the names of its contributors may be
15 used to endorse or promote products derived from this software without
16 specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 POSSIBILITY OF SUCH DAMAGE.
35 /* On platforms where long double is as wide as double. */
36 #if defined(_LDBL_EQ_DBL)
38 frexpl (long double x
, int *eptr
)
40 return frexp(x
, eptr
);
42 #else /* !_DBL_EQ_DBL */
43 # if (LDBL_MANT_DIG == 53) /* 64-bit long double */
44 static const double scale
= 0x1p
54;
49 # ifdef __IEEE_LITTLE_ENDIAN /* for Intel CPU */
55 # ifdef __IEEE_BIG_ENDIAN
59 # ifndef ___IEEE_BYTES_LITTLE_ENDIAN
60 # else /* ARMEL without __VFP_FP__ */
69 # elif (LDBL_MANT_DIG == 64) /* 80-bit long double */
70 static const double scale
= 0x1p
65;
75 # ifdef __IEEE_LITTLE_ENDIAN /* for Intel CPU */
82 # ifdef __IEEE_BIG_ENDIAN
83 # ifndef ___IEEE_BYTES_LITTLE_ENDIAN /* for m86k */
87 # else /* ARM FPA10 math copprocessor */
97 # elif (LDBL_MANT_DIG == 113) /* 128-bit long double */
98 static const double scale
= 0x1p
114;
103 # ifdef __IEEE_LITTLE_ENDIAN
111 # ifdef __IEEE_BIG_ENDIAN
112 # ifndef ___IEEE_BYTES_LITTLE_ENDIAN
116 # else /* ARMEL without __VFP_FP__ */
128 # error Unsupported long double format.
131 static const int scale_exp
= LDBL_MANT_DIG
+ 1;
134 frexpl (long double x
, int *eptr
)
140 if (e
== (LDBL_MAX_EXP
*2 - 1) || x
== 0)
141 return x
; /* inf,nan,0 */
142 if (e
== 0) /* subnormal */
148 *eptr
+= e
- (LDBL_MAX_EXP
- 2);
149 u
.u32
.exp
= LDBL_MAX_EXP
- 2; /* -1 */
152 #endif /* !_LDBL_EQ_DBL */