Various refactorings around bignum arithmetic
This commit is contained in:
parent
d624c671cd
commit
7f93b04b72
6 changed files with 134 additions and 85 deletions
23
src/debug.c
23
src/debug.c
|
|
@ -42,6 +42,29 @@ void debug_print( wchar_t *message, int level ) {
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* stolen from https://stackoverflow.com/questions/11656241/how-to-print-uint128-t-number-using-gcc
|
||||
*/
|
||||
void debug_print_128bit( __int128_t n, int level ) {
|
||||
#ifdef DEBUG
|
||||
if ( level & verbosity ) {
|
||||
if (n == 0) {
|
||||
fwprintf(stderr, L"0");
|
||||
} else {
|
||||
char str[40] = {0}; // log10(1 << 128) + '\0'
|
||||
char *s = str + sizeof(str) - 1; // start at the end
|
||||
while (n != 0) {
|
||||
if (s == str) return; // never happens
|
||||
|
||||
*--s = "0123456789"[n % 10]; // save last digit
|
||||
n /= 10; // drop it
|
||||
}
|
||||
fwprintf(stderr, L"%s", s);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* print a line feed to stderr, if `verbosity` matches `level`.
|
||||
* `verbosity is a set of flags, see debug_print.h; so you can
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue