1 /* Copyright (C) 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
26 /* Convert a `long double' in IEEE854 standard double-precision format to a
27 multi-precision integer representing the significand scaled up by its
28 number of bits (64 for long double) and an integral power of two
32 __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
33 int *expt, int *is_neg,
36 union ieee854_long_double u;
39 *is_neg = u.ieee.negative;
40 *expt = (int) u.ieee.exponent - IEEE854_LONG_DOUBLE_BIAS;
42 #if BITS_PER_MP_LIMB == 32
43 res_ptr[0] = u.ieee.mantissa1; /* Low-order 32 bits of fraction. */
44 res_ptr[1] = u.ieee.mantissa0; /* High-order 32 bits. */
46 #elif BITS_PER_MP_LIMB == 64
47 /* Hopefully the compiler will combine the two bitfield extracts
48 and this composition into just the original quadword extract. */
49 res_ptr[0] = (u.ieee.mantissa0 << 32) | u.ieee.mantissa1;
52 #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
55 if (u.ieee.exponent == 0)
57 /* A biased exponent of zero is a special case.
58 Either it is a zero or it is a denormal number. */
59 if (res_ptr[0] == 0 && res_ptr[N - 1] == 0) /* Assumes N<=2. */
64 /* It is a denormal number, meaning it has no implicit leading
65 one bit, and its exponent is in fact the format minimum. */
67 if (res_ptr[N - 1] != 0)
69 count_leading_zeros (cnt, res_ptr[N - 1]);
73 res_ptr[N - 1] = res_ptr[N - 1] << cnt
74 | (res_ptr[0] >> (BITS_PER_MP_LIMB - cnt));
77 res_ptr[N - 1] <<= cnt;
80 *expt = LDBL_MIN_EXP - 2 - cnt;
84 count_leading_zeros (cnt, res_ptr[0]);
85 res_ptr[N - 1] = res_ptr[0] << cnt;
87 *expt = LDBL_MIN_EXP - 2 - BITS_PER_MP_LIMB - cnt;