summaryrefslogtreecommitdiffstats
path: root/generic/tclTomMathInterface.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-10-08 14:42:44 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-10-08 14:42:44 (GMT)
commit76faac0f28fe9661f23ff9e35f44df1d899420e5 (patch)
tree7e3de1d0523d70328cfd81d9864b897058823d34 /generic/tclTomMathInterface.c
parent98a6fcad96289a40b501fbd2095387a245fd804d (diff)
downloadtcl-76faac0f28fe9661f23ff9e35f44df1d899420e5.zip
tcl-76faac0f28fe9661f23ff9e35f44df1d899420e5.tar.gz
tcl-76faac0f28fe9661f23ff9e35f44df1d899420e5.tar.bz2
TIP#237 IMPLEMENTATION
[kennykb-numerics-branch] Resynchronized with the HEAD; at this checkpoint [-rkennykb-numerics-branch-20051008], the HEAD and kennykb-numerics-branch contain identical code.
Diffstat (limited to 'generic/tclTomMathInterface.c')
-rw-r--r--generic/tclTomMathInterface.c82
1 files changed, 81 insertions, 1 deletions
diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c
index 89537b9..7eda5c3 100644
--- a/generic/tclTomMathInterface.c
+++ b/generic/tclTomMathInterface.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclTomMathInterface.c,v 1.2 2005/05/10 18:34:51 kennykb Exp $
+ * RCS: @(#) $Id: tclTomMathInterface.c,v 1.3 2005/10/08 14:42:45 dgp Exp $
*/
#include "tclInt.h"
@@ -141,3 +141,83 @@ TclBNInitBignumFromLong( mp_int* a, long initVal )
a->used = p - a->dp;
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclBNInitBignumFromWideInt --
+ *
+ * Allocate and initialize a 'bignum' from a Tcl_WideInt
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The 'bignum' is constructed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+extern void
+TclBNInitBignumFromWideInt(mp_int* a,
+ /* Bignum to initialize */
+ Tcl_WideInt v)
+ /* Initial value */
+{
+ if (v < (Tcl_WideInt)0) {
+ TclBNInitBignumFromWideUInt(a, (Tcl_WideUInt)(-v));
+ mp_neg(a, a);
+ } else {
+ TclBNInitBignumFromWideUInt(a, (Tcl_WideUInt)v);
+ }
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclBNInitBignumFromWideUInt --
+ *
+ * Allocate and initialize a 'bignum' from a Tcl_WideUInt
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The 'bignum' is constructed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+extern void
+TclBNInitBignumFromWideUInt(mp_int* a,
+ /* Bignum to initialize */
+ Tcl_WideUInt v)
+ /* Initial value */
+{
+
+ int status;
+ mp_digit* p;
+
+ /*
+ * Allocate enough memory to hold the largest possible Tcl_WideUInt
+ */
+
+ status = mp_init_size(a, ((CHAR_BIT * sizeof( Tcl_WideUInt )
+ + DIGIT_BIT - 1)
+ / DIGIT_BIT));
+ if (status != MP_OKAY) {
+ Tcl_Panic( "initialization failure in TclBNInitBignumFromWideUInt" );
+ }
+
+ a->sign = MP_ZPOS;
+
+ /* Store the magnitude in the bignum. */
+
+ p = a->dp;
+ while ( v ) {
+ *p++ = (mp_digit) ( v & MP_MASK );
+ v >>= MP_DIGIT_BIT;
+ }
+ a->used = p - a->dp;
+
+}