1 /* __gmp_extract_double -- convert from double to array of mp_limb_t.
3 Copyright (C) 1996 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Library General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
27 #undef _GMP_IEEE_FLOATS
30 #ifndef _GMP_IEEE_FLOATS
31 #define _GMP_IEEE_FLOATS 0
34 #define MP_BASE_AS_DOUBLE (2.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)))
36 /* Extract a non-negative double in d. */
40 __gmp_extract_double (mp_ptr rp, double d)
42 __gmp_extract_double (rp, d)
53 1. Should handle Inf and NaN in IEEE specific code.
54 2. Handle Inf and NaN also in default code, to avoid hangs.
55 3. Generalize to handle all BITS_PER_MP_LIMB >= 32.
56 4. This lits is incomplete and misspelled.
63 #if BITS_PER_MP_LIMB == 32
71 union ieee_double_extract x;
75 sc = (unsigned) (exp + 2) % BITS_PER_MP_LIMB;
76 #if BITS_PER_MP_LIMB == 64
77 manl = (((mp_limb_t) 1 << 63)
78 | ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11));
80 manh = ((mp_limb_t) 1 << 31) | (x.s.manh << 11) | (x.s.manl >> 21);
81 manl = x.s.manl << 11;
86 /* Unknown (or known to be non-IEEE) double format. */
106 while (d < (1.0 / 65536.0))
118 sc = (unsigned) exp % BITS_PER_MP_LIMB;
120 d *= MP_BASE_AS_DOUBLE;
121 #if BITS_PER_MP_LIMB == 64
125 manl = (d - manh) * MP_BASE_AS_DOUBLE;
132 exp = (unsigned) (exp + 1) / BITS_PER_MP_LIMB - 1024 / BITS_PER_MP_LIMB + 1;
134 #if BITS_PER_MP_LIMB == 64
137 rp[1] = manl >> (BITS_PER_MP_LIMB - sc);
148 rp[2] = manh >> (BITS_PER_MP_LIMB - sc);
149 rp[1] = (manl >> (BITS_PER_MP_LIMB - sc)) | (manh << sc);