beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpf / get_d_2exp.c
blob17ce229f2511f9f2d0b3c8299da9b8fccd6a5349
1 /* double mpf_get_d_2exp (signed long int *exp, mpf_t src).
3 Copyright 2001-2004 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 either:
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
16 * the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any
18 later version.
20 or both in parallel, as here.
22 The GNU MP Library is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 for more details.
27 You should have received copies of the GNU General Public License and the
28 GNU Lesser General Public License along with the GNU MP Library. If not,
29 see https://www.gnu.org/licenses/. */
31 #include "gmp.h"
32 #include "gmp-impl.h"
33 #include "longlong.h"
36 double
37 mpf_get_d_2exp (signed long int *exp2, mpf_srcptr src)
39 mp_size_t size, abs_size;
40 mp_srcptr ptr;
41 int cnt;
42 long exp;
44 size = SIZ(src);
45 if (UNLIKELY (size == 0))
47 *exp2 = 0;
48 return 0.0;
51 ptr = PTR(src);
52 abs_size = ABS (size);
53 count_leading_zeros (cnt, ptr[abs_size - 1]);
54 cnt -= GMP_NAIL_BITS;
56 exp = EXP(src) * GMP_NUMB_BITS - cnt;
57 *exp2 = exp;
59 return mpn_get_d (ptr, abs_size, (mp_size_t) 0,
60 (long) - (abs_size * GMP_NUMB_BITS - cnt));