summaryrefslogtreecommitdiff
path: root/mpf
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2001-11-28 20:45:47 +0100
committertege <tege@gmplib.org>2001-11-28 20:45:47 +0100
commite883fe12673d4f3781733f044e269559ead1ca58 (patch)
treeed0c2a053073f55668a51ec3ff33f46e186aa6c8 /mpf
parent065bd099f808c30a4320e2f350dbe163fff765a2 (diff)
downloadgmp-e883fe12673d4f3781733f044e269559ead1ca58.tar.gz
*** empty log message ***
Diffstat (limited to 'mpf')
-rw-r--r--mpf/get_d_2exp.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/mpf/get_d_2exp.c b/mpf/get_d_2exp.c
new file mode 100644
index 000000000..92e3a2edc
--- /dev/null
+++ b/mpf/get_d_2exp.c
@@ -0,0 +1,56 @@
+/* double mpf_get_d_2exp (signed long int *exp, mpf_t src).
+
+Copyright 2001 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "longlong.h"
+
+double
+mpf_get_d_2exp (signed long int *exp2, mpf_srcptr src)
+{
+ double res;
+ mp_size_t size, i, n_limbs_to_use;
+ int negative;
+ mp_ptr qp;
+ int cnt;
+
+ size = SIZ(src);
+ if (size == 0)
+ {
+ *exp2 = 0;
+ return 0.0;
+ }
+
+ negative = size < 0;
+ size = ABS (size);
+ qp = PTR(src);
+
+ n_limbs_to_use = MIN (LIMBS_PER_DOUBLE, size);
+ qp += size - n_limbs_to_use;
+ res = qp[0] / MP_BASE_AS_DOUBLE;
+ for (i = 1; i < n_limbs_to_use; i++)
+ res = (res + qp[i]) / MP_BASE_AS_DOUBLE;
+ count_leading_zeros (cnt, qp[n_limbs_to_use - 1]);
+ *exp2 = EXP(src) * BITS_PER_MP_LIMB - cnt;
+ res = res * ((mp_limb_t) 1 << cnt);
+
+ return negative ? -res : res;
+}