diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-03-20 20:59:12 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-03-20 20:59:12 -0700 |
commit | fe69004a3798e896cf7349149c6c37ec58676b45 (patch) | |
tree | 4c4e933826096a497cf92b06791779f7a213a149 /mpi-patches/mpi-to-double | |
parent | 270dcc27814f4bd80f625b85e9ff91e7c5a8e8a8 (diff) | |
download | txr-fe69004a3798e896cf7349149c6c37ec58676b45.tar.gz txr-fe69004a3798e896cf7349149c6c37ec58676b45.tar.bz2 txr-fe69004a3798e896cf7349149c6c37ec58676b45.zip |
* arith.c (flo_int): New function.
* eval.c (eval_init): flo-int registered as intrinsic.
* lib.h (flo_int): Declared.
* mpi-patches/series: Added mpi-to-double to patch stack.
(mp_to_double): New MPI function.
* mpi-patches/mpi-to-double: New file.
Diffstat (limited to 'mpi-patches/mpi-to-double')
-rw-r--r-- | mpi-patches/mpi-to-double | 58 |
1 files changed, 58 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 |