]> pd.if.org Git - zpackage/blobdiff - tomsfastmath/src/exptmod/fp_2expt.c
commit files needed for zpm-fetchurl
[zpackage] / tomsfastmath / src / exptmod / fp_2expt.c
diff --git a/tomsfastmath/src/exptmod/fp_2expt.c b/tomsfastmath/src/exptmod/fp_2expt.c
new file mode 100644 (file)
index 0000000..a6ed603
--- /dev/null
@@ -0,0 +1,39 @@
+/* TomsFastMath, a fast ISO C bignum library.
+ * 
+ * This project is meant to fill in where LibTomMath
+ * falls short.  That is speed ;-)
+ *
+ * This project is public domain and free for all purposes.
+ * 
+ * Tom St Denis, tomstdenis@gmail.com
+ */
+#include <tfm_private.h>
+
+/* computes a = 2**b */
+void fp_2expt(fp_int *a, int b)
+{
+   int     z;
+
+   /* zero a as per default */
+   fp_zero (a);
+
+   if (b < 0) { 
+      return;
+   }
+
+   z = b / DIGIT_BIT;
+   if (z >= FP_SIZE) {
+      return; 
+   }
+
+  /* set the used count of where the bit will go */
+  a->used = z + 1;
+
+  /* put the single bit in its place */
+  a->dp[z] = ((fp_digit)1) << (b % DIGIT_BIT);
+}
+
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */