summaryrefslogtreecommitdiffstats
path: root/mpi
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-04-22 19:54:38 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-04-22 19:54:38 -0700
commitec1bb5b3d2ee3e50dd2956595dd7cf8b82de64ff (patch)
treef862c70132009115ad634712a09324756ed751b5 /mpi
parent0ee6428c2ddf94b758bf6005f1bae593c7a0366c (diff)
downloadtxr-ec1bb5b3d2ee3e50dd2956595dd7cf8b82de64ff.tar.gz
txr-ec1bb5b3d2ee3e50dd2956595dd7cf8b82de64ff.tar.bz2
txr-ec1bb5b3d2ee3e50dd2956595dd7cf8b82de64ff.zip
mpi-set-double-intptr patch
* mpi/mpi.c (mp_set_double_intptr): New function. * mpi/mpi.h (mp_set_double_intptr): Declared.
Diffstat (limited to 'mpi')
-rw-r--r--mpi/mpi.c30
-rw-r--r--mpi/mpi.h3
2 files changed, 33 insertions, 0 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index 93a97331..7a721e3b 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -571,6 +571,36 @@ mp_err mp_get_intptr(mp_int *mp, int_ptr_t *z)
return MP_OKAY;
}
+#ifdef HAVE_DOUBLE_INTPTR_T
+mp_err mp_set_double_intptr(mp_int *mp, double_intptr_t z)
+{
+ int ix, shift;
+ double_intptr_t v = z > 0 ? z : -z;
+ const int nd = (sizeof v + sizeof (mp_digit) - 1) / sizeof (mp_digit);
+
+ ARGCHK(mp != NULL, MP_BADARG);
+
+ mp_zero(mp);
+
+ if(z == 0)
+ return MP_OKAY; /* shortcut for zero */
+
+ s_mp_grow(mp, nd);
+
+ USED(mp) = nd;
+
+ for (ix = 0, shift = 0; ix < nd; ix++, shift += MP_DIGIT_BIT)
+ {
+ DIGIT(mp, ix) = (v >> shift) & MP_DIGIT_MAX;
+ }
+
+ if(z < 0)
+ SIGN(mp) = MP_NEG;
+
+ return MP_OKAY;
+}
+#endif
+
mp_err mp_set_word(mp_int *mp, mp_word w, int sign)
{
USED(mp) = 2;
diff --git a/mpi/mpi.h b/mpi/mpi.h
index 91fb967d..e4a6cec2 100644
--- a/mpi/mpi.h
+++ b/mpi/mpi.h
@@ -100,6 +100,9 @@ void mp_set(mp_int *mp, mp_digit d);
mp_err mp_set_int(mp_int *mp, long z);
mp_err mp_set_intptr(mp_int *mp, int_ptr_t z);
mp_err mp_get_intptr(mp_int *mp, int_ptr_t *z);
+#ifdef HAVE_DOUBLE_INTPTR_T
+mp_err mp_set_double_intptr(mp_int *mp, double_intptr_t z);
+#endif
mp_err mp_set_word(mp_int *mp, mp_word w, int sign);
/*------------------------------------------------------------------------*/