summaryrefslogtreecommitdiffstats
path: root/mpi-patches
diff options
context:
space:
mode:
Diffstat (limited to 'mpi-patches')
-rw-r--r--mpi-patches/mpi-to-double58
-rw-r--r--mpi-patches/series1
2 files changed, 59 insertions, 0 deletions
diff --git a/mpi-patches/mpi-to-double b/mpi-patches/mpi-to-double
new file mode 100644
index 00000000..653d612c
--- /dev/null
+++ b/mpi-patches/mpi-to-double
@@ -0,0 +1,58 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2012-03-20 20:23:46.604727758 -0700
++++ mpi-1.8.6/mpi.c 2012-03-20 20:37:28.514792258 -0700
+@@ -14,6 +14,7 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <ctype.h>
++#include <math.h>
+
+ typedef unsigned char mem_t;
+ extern mem_t *chk_malloc(size_t size);
+@@ -2329,6 +2330,29 @@
+
+ /* }}} */
+
++mp_err mp_to_double(mp_int *mp, double *d)
++{
++ int ix;
++ mp_size used = USED(mp);
++ mp_digit *dp = DIGITS(mp);
++ static double mult;
++ double out = dp[used - 1];
++
++ if (!mult)
++ mult = pow(2.0, MP_DIGIT_BIT);
++
++ for (ix = (int) used - 2; ix >= 0; ix++) {
++ out = out * mult;
++ out += (double) dp[ix];
++ }
++
++ if (SIGN(mp) == MP_NEG)
++ out = -out;
++
++ *d = out;
++ return MP_OKAY;
++}
++
+ /*------------------------------------------------------------------------*/
+ /* {{{ mp_print(mp, ofp) */
+
+Index: mpi-1.8.6/mpi.h
+===================================================================
+--- mpi-1.8.6.orig/mpi.h 2012-03-20 20:23:39.184556258 -0700
++++ mpi-1.8.6/mpi.h 2012-03-20 20:25:30.018865508 -0700
+@@ -187,6 +187,11 @@
+ #endif /* end MP_NUMTH */
+
+ /*------------------------------------------------------------------------*/
++/* Conversions */
++
++mp_err mp_to_double(mp_int *mp, double *d);
++
++/*------------------------------------------------------------------------*/
+ /* Input and output */
+
+ #if MP_IOFUNC
diff --git a/mpi-patches/series b/mpi-patches/series
index 0181c920..c880ab60 100644
--- a/mpi-patches/series
+++ b/mpi-patches/series
@@ -12,3 +12,4 @@ fix-bad-shifts
bit-search-optimizations
shrink-mpi-int
faster-square-root
+mpi-to-double