From fac7ff6e6061b1eb0e699756e3d08859f71884e8 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 10 May 2017 21:19:54 +0100 Subject: [PATCH] math/scaf.c: Add some debugging utilities I found handy. --- math/scaf.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/math/scaf.c b/math/scaf.c index 84ef3de8..2f88a306 100644 --- a/math/scaf.c +++ b/math/scaf.c @@ -31,6 +31,52 @@ #include "scaf.h" +/*----- Debugging utilties ------------------------------------------------*/ + +#ifdef SCAF_DEBUG + +#include + +#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@ --- * -- 2.11.0