math/scaf.c: Add some debugging utilities I found handy.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 10 May 2017 20:19:54 +0000 (21:19 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 13:58:41 +0000 (14:58 +0100)
math/scaf.c

index 84ef3de..2f88a30 100644 (file)
 
 #include "scaf.h"
 
+/*----- Debugging utilties ------------------------------------------------*/
+
+#ifdef SCAF_DEBUG
+
+#include <stdio.h>
+
+#include "mp.h"
+#include "mpint.h"
+#include "mptext.h"
+
+static void scaf_dump(const char *what, const scaf_piece *x,
+                     size_t npiece, size_t piecewd)
+{
+  mp *y = MP_ZERO, *t = MP_NEW;
+  size_t i;
+  unsigned o = 0;
+
+  for (i = 0; i < npiece; i++) {
+    t = mp_fromuint64(t, x[i]);
+    t = mp_lsl(t, t, o);
+    y = mp_add(y, y, t);
+    o += piecewd;
+  }
+  printf(";; %s", what); MP_PRINT("", y); putchar('\n');
+  mp_drop(y); mp_drop(t);
+}
+
+static void scaf_dumpdbl(const char *what, const scaf_dblpiece *x,
+                     size_t npiece, size_t piecewd)
+{
+  mp *y = MP_ZERO, *t = MP_NEW;
+  size_t i;
+  unsigned o = 0;
+
+  for (i = 0; i < npiece; i++) {
+    t = mp_fromuint64(t, x[i]);
+    t = mp_lsl(t, t, o);
+    y = mp_add(y, y, t);
+    o += piecewd;
+  }
+  printf(";; %s", what); MP_PRINT("", y); putchar('\n');
+  mp_drop(y); mp_drop(t);
+}
+
+#endif
+
 /*----- Main code ---------------------------------------------------------*/
 
 /* --- @scaf_load@ --- *