diff options
75 files changed, 2193 insertions, 2216 deletions
diff --git a/acinclude.m4 b/acinclude.m4 index 2e0e0c121..86d3824d8 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -222,7 +222,7 @@ fi], fi fi]) ]) - + dnl GMP_PROG_AR dnl ----------- @@ -286,7 +286,7 @@ dnl and an AC_SUBST accordingly. If $M4 is already set then it's a user dnl choice and is accepted with no checks. GMP_PROG_M4 is like dnl AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's dnl good enough. -dnl +dnl dnl See mpn/asm-defs.m4 for details on the known bad m4s. AC_DEFUN([GMP_PROG_M4], @@ -1159,7 +1159,7 @@ if AC_TRY_EVAL(gmp_compile); then if grep "Unknown CPU identifier" conftest.out >/dev/null; then : ; else result=yes - fi + fi fi cat conftest.out >&AC_FD_CC rm -f conftest* @@ -1488,7 +1488,7 @@ case $srcdir in esac echo ["define(<CONFIG_TOP_SRCDIR>,<\`$tmp'>)"] >>$gmp_tmpconfigm4 -# All CPUs use asm-defs.m4 +# All CPUs use asm-defs.m4 echo ["include][(CONFIG_TOP_SRCDIR\`/mpn/asm-defs.m4')"] >>$gmp_tmpconfigm4i ]) @@ -1560,7 +1560,7 @@ dnl variables will get expanded. Don't forget to invoke GMP_FINISH to dnl create file config.m4. config.m4 uses `<' and '>' as quote characters dnl for all defines. -AC_DEFUN([GMP_DEFINE], +AC_DEFUN([GMP_DEFINE], [AC_REQUIRE([GMP_INIT]) echo ['define(<$1>, <$2>)'] >>ifelse([$3], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4) @@ -1663,7 +1663,7 @@ dnl good reason for nm to fail though. AC_DEFUN([GMP_ASM_UNDERSCORE], [AC_REQUIRE([GMP_PROG_NM]) -AC_CACHE_CHECK([if globals are prefixed by underscore], +AC_CACHE_CHECK([if globals are prefixed by underscore], gmp_cv_asm_underscore, [gmp_cv_asm_underscore="unknown" cat >conftest.c <<EOF @@ -1946,7 +1946,7 @@ dnl dnl other - .globl is usual. dnl dnl "gas" tends to accept .globl everywhere, in addition to .export or -dnl .global or whatever the system assembler demands. +dnl .global or whatever the system assembler demands. AC_DEFUN([GMP_ASM_GLOBL], [AC_REQUIRE([GMP_ASM_TEXT]) @@ -2137,7 +2137,7 @@ AC_DEFUN([GMP_ASM_LSYM_PREFIX], [AC_REQUIRE([GMP_ASM_LABEL_SUFFIX]) AC_REQUIRE([GMP_ASM_TEXT]) AC_REQUIRE([GMP_PROG_NM]) -AC_CACHE_CHECK([for assembler local label prefix], +AC_CACHE_CHECK([for assembler local label prefix], gmp_cv_asm_lsym_prefix, [gmp_tmp_pre_appears=yes for gmp_tmp_pre in L .L $ L$; do @@ -2200,7 +2200,7 @@ AC_REQUIRE([GMP_ASM_LABEL_SUFFIX]) AC_REQUIRE([GMP_PROG_NM]) AC_CACHE_CHECK([how to define a 32-bit word], gmp_cv_asm_w32, -[case $host in +[case $host in *-*-hpux*) # FIXME: HPUX puts first symbol at 0x40000000, breaking our assumption # that it's at 0x0. We'll have to declare another symbol before the @@ -2283,7 +2283,7 @@ AC_REQUIRE([GMP_ASM_GLOBL_ATTR]) AC_REQUIRE([GMP_ASM_LABEL_SUFFIX]) AC_REQUIRE([GMP_ASM_UNDERSCORE]) AC_REQUIRE([AC_LIBTOOL_PROG_COMPILER_PIC]) -AC_CACHE_CHECK([if _GLOBAL_OFFSET_TABLE_ is prefixed by underscore], +AC_CACHE_CHECK([if _GLOBAL_OFFSET_TABLE_ is prefixed by underscore], gmp_cv_asm_x86_got_underscore, [gmp_cv_asm_x86_got_underscore="not applicable" if test $gmp_cv_asm_underscore = yes; then @@ -2314,7 +2314,7 @@ if test "$gmp_cv_asm_x86_got_underscore" = "yes"; then GMP_DEFINE(GOT_GSYM_PREFIX, [_]) else GMP_DEFINE(GOT_GSYM_PREFIX, []) -fi +fi ]) @@ -3585,7 +3585,7 @@ die die die [case $ac_cv_c_inline in yes) tmp_inline=inline ;; *) tmp_inline=$ac_cv_c_inline ;; - esac + esac AC_MSG_WARN([gmp.h doesnt recognise compiler "$tmp_inline", inlines will be unavailable])]) ;; esac @@ -3636,7 +3636,7 @@ else AC_MSG_ERROR([Cannot find a build system compiler]) fi fi - + AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler]) AC_SUBST(CC_FOR_BUILD) ]) diff --git a/demos/calc/calcread.c b/demos/calc/calcread.c index ca8395e10..53291ff73 100644 --- a/demos/calc/calcread.c +++ b/demos/calc/calcread.c @@ -30,7 +30,7 @@ this program. If not, see http://www.gnu.org/licenses/. */ /* change this to "#define TRACE(x) x" for a few diagnostics */ -#define TRACE(x) +#define TRACE(x) #define MIN(x,y) ((x) < (y) ? (x) : (y)) @@ -47,12 +47,12 @@ calc_completion_entry (const char *text, int state) len = strlen (text); } TRACE (printf ("calc_completion_entry %s %d, index=%d len=%d\n", - text, state, index, len)); + text, state, index, len)); while ((name = calc_keywords[index].name) != NULL) { index++; if (memcmp (name, text, len) == 0) - return (strdup (name)); + return (strdup (name)); } return NULL; } @@ -95,24 +95,24 @@ calc_input (char *buf, size_t max_size) size_t copy_size; if (upto >= line_size) - { - if (line != NULL) - free (line); - - line = readline (calc_more_input ? "more> " : "> "); - calc_more_input = 1; - if (line == NULL) - return 0; - TRACE (printf ("readline: %s\n", line)); - - if (line[0] != '\0') - add_history (line); - - line_size = strlen (line); - line[line_size] = '\n'; - line_size++; - upto = 0; - } + { + if (line != NULL) + free (line); + + line = readline (calc_more_input ? "more> " : "> "); + calc_more_input = 1; + if (line == NULL) + return 0; + TRACE (printf ("readline: %s\n", line)); + + if (line[0] != '\0') + add_history (line); + + line_size = strlen (line); + line[line_size] = '\n'; + line_size++; + upto = 0; + } copy_size = MIN (line_size-upto, max_size); memcpy (buf, line+upto, copy_size); diff --git a/demos/expr/README b/demos/expr/README index a6bdfa0cf..2283cd3ff 100644 --- a/demos/expr/README +++ b/demos/expr/README @@ -411,7 +411,7 @@ where. static const struct mpexpr_operator_t table[] = { { "^", (mpexpr_fun_t) mpz_pow_ui, MPEXPR_TYPE_BINARY_UI | MPEXPR_TYPE_RIGHTASSOC, 9 }, - + { "!", (mpexpr_fun_t) mpz_fac_ui, MPEXPR_TYPE_UNARY_UI, 8 }, { "-", (mpexpr_fun_t) mpz_neg, MPEXPR_TYPE_UNARY | MPEXPR_TYPE_PREFIX, 7 }, diff --git a/demos/expr/expr.c b/demos/expr/expr.c index e87ba6087..f78c32173 100644 --- a/demos/expr/expr.c +++ b/demos/expr/expr.c @@ -31,7 +31,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ mpz/mpq/mpf being run (if you have the wrong trace function it'll probably segv). */ -#define TRACE(x) +#define TRACE(x) #define MPX_TRACE mpz_trace @@ -77,17 +77,17 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ do { \ if (p->data_top + 1 >= p->data_alloc) \ { \ - void *(*reallocate_func) (void *, size_t, size_t); \ - mp_get_memory_functions (NULL, &reallocate_func, NULL); \ - TRACE (printf ("grow stack from %d\n", p->data_alloc)); \ - REALLOC (p->data_stack, p->data_alloc, 20, union mpX_t); \ + void *(*reallocate_func) (void *, size_t, size_t); \ + mp_get_memory_functions (NULL, &reallocate_func, NULL); \ + TRACE (printf ("grow stack from %d\n", p->data_alloc)); \ + REALLOC (p->data_stack, p->data_alloc, 20, union mpX_t); \ } \ ASSERT (p->data_top + 1 <= p->data_inited); \ if (p->data_top + 1 == p->data_inited) \ { \ - TRACE (printf ("initialize %d\n", p->data_top + 1)); \ - (*p->mpX_init) (&p->data_stack[p->data_top + 1], p->prec); \ - p->data_inited++; \ + TRACE (printf ("initialize %d\n", p->data_top + 1)); \ + (*p->mpX_init) (&p->data_stack[p->data_top + 1], p->prec); \ + p->data_inited++; \ } \ } while (0) @@ -159,38 +159,38 @@ lookahead (struct mpexpr_parse_t *p, int prefix) break; TRACE (printf ("lookahead at: \"%.*s\" length %u, word %u\n", - (int) p->elen, p->e, p->elen, wlen)); + (int) p->elen, p->e, p->elen, wlen)); op_found = NULL; oplen_found = 0; for (op = p->table; op->name != NULL; op++) { if (op->type == MPEXPR_TYPE_NEW_TABLE) - { - printf ("new\n"); - op = (struct mpexpr_operator_t *) op->name - 1; - continue; - } + { + printf ("new\n"); + op = (struct mpexpr_operator_t *) op->name - 1; + continue; + } oplen = strlen (op->name); if (! ((WHOLEWORD (op) ? wlen == oplen : p->elen >= oplen) - && memcmp (p->e, op->name, oplen) == 0)) - continue; + && memcmp (p->e, op->name, oplen) == 0)) + continue; /* Shorter matches don't replace longer previous ones. */ if (op_found && oplen < oplen_found) - continue; + continue; /* On a match of equal length to a previous one, the old match isn't - replaced if it has the preferred prefix, and if it doesn't then - it's not replaced if the new one also doesn't. */ + replaced if it has the preferred prefix, and if it doesn't then + it's not replaced if the new one also doesn't. */ if (op_found && oplen == oplen_found - && ((op_found->type & MPEXPR_TYPE_PREFIX) == prefix - || (op->type & MPEXPR_TYPE_PREFIX) != prefix)) - continue; + && ((op_found->type & MPEXPR_TYPE_PREFIX) == prefix + || (op->type & MPEXPR_TYPE_PREFIX) != prefix)) + continue; /* This is now either the first match seen, or a longer than previous - match, or an equal to previous one but with a preferred prefix. */ + match, or an equal to previous one but with a preferred prefix. */ op_found = op; oplen_found = oplen; } @@ -200,30 +200,30 @@ lookahead (struct mpexpr_parse_t *p, int prefix) p->e += oplen_found, p->elen -= oplen_found; if (op_found->type == MPEXPR_TYPE_VARIABLE) - { - if (p->elen == 0) - ERROR ("end of string expecting a variable", - MPEXPR_RESULT_PARSE_ERROR); - i = p->e[0] - 'a'; - if (i < 0 || i >= MPEXPR_VARIABLES) - ERROR ("bad variable name", MPEXPR_RESULT_BAD_VARIABLE); - goto variable; - } + { + if (p->elen == 0) + ERROR ("end of string expecting a variable", + MPEXPR_RESULT_PARSE_ERROR); + i = p->e[0] - 'a'; + if (i < 0 || i >= MPEXPR_VARIABLES) + ERROR ("bad variable name", MPEXPR_RESULT_BAD_VARIABLE); + goto variable; + } if (op_found->precedence == 0) - { - TRACE (printf ("lookahead function: %s\n", op_found->name)); - p->token = TOKEN_FUNCTION; - p->token_op = op_found; - return 1; - } + { + TRACE (printf ("lookahead function: %s\n", op_found->name)); + p->token = TOKEN_FUNCTION; + p->token_op = op_found; + return 1; + } else - { - TRACE (printf ("lookahead operator: %s\n", op_found->name)); - p->token = TOKEN_OPERATOR; - p->token_op = op_found; - return 1; - } + { + TRACE (printf ("lookahead operator: %s\n", op_found->name)); + p->token = TOKEN_OPERATOR; + p->token_op = op_found; + return 1; + } } oplen = (*p->mpX_number) (SP+1, p->e, p->elen, p->base); @@ -243,9 +243,9 @@ lookahead (struct mpexpr_parse_t *p, int prefix) variable: p->e++, p->elen--; if (p->var[i] == NULL) - ERROR ("NULL variable", MPEXPR_RESULT_BAD_VARIABLE); + ERROR ("NULL variable", MPEXPR_RESULT_BAD_VARIABLE); TRACE (printf ("lookahead variable: var[%d] = ", i); - MPX_TRACE ("", p->var[i])); + MPX_TRACE ("", p->var[i])); p->token = TOKEN_VALUE; DATA_PUSH (); (*p->mpX_set) (SP, p->var[i]); @@ -267,9 +267,9 @@ lookahead (struct mpexpr_parse_t *p, int prefix) do { \ if (p->control_top + 1 >= p->control_alloc) \ { \ - TRACE (printf ("grow control stack from %d\n", p->control_alloc)); \ - REALLOC (p->control_stack, p->control_alloc, 20, \ - struct mpexpr_control_t); \ + TRACE (printf ("grow control stack from %d\n", p->control_alloc)); \ + REALLOC (p->control_stack, p->control_alloc, 20, \ + struct mpexpr_control_t); \ } \ } while (0) @@ -303,8 +303,8 @@ lookahead (struct mpexpr_parse_t *p, int prefix) printf ("%s depth %d:", str, p->control_top); \ for (i = 0; i <= p->control_top; i++) \ printf (" \"%s\"(%d)", \ - p->control_stack[i].op->name, \ - p->control_stack[i].argcount); \ + p->control_stack[i].op->name, \ + p->control_stack[i].argcount); \ printf ("\n"); \ }); @@ -325,9 +325,9 @@ lookahead (struct mpexpr_parse_t *p, int prefix) do { \ if (CP->argcount != (n)) \ { \ - TRACE (printf ("wrong number of arguments for %s, got %d want %d", \ - str, CP->argcount, n)); \ - ERROR ("", MPEXPR_RESULT_PARSE_ERROR); \ + TRACE (printf ("wrong number of arguments for %s, got %d want %d", \ + str, CP->argcount, n)); \ + ERROR ("", MPEXPR_RESULT_PARSE_ERROR); \ } \ } while (0) @@ -366,7 +366,7 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) mp_get_memory_functions (&allocate_func, &reallocate_func, &free_func); TRACE (printf ("mpexpr_evaluate() base %d \"%.*s\"\n", - p->base, (int) p->elen, p->e)); + p->base, (int) p->elen, p->e)); /* "done" is a special sentinel at the bottom of the control stack, precedence -1 is lower than any normal operator. */ @@ -376,7 +376,7 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) p->control_alloc = 20; p->control_stack = ALLOCATE_FUNC_TYPE (p->control_alloc, - struct mpexpr_control_t); + struct mpexpr_control_t); p->control_top = 0; CP->op = &operator_done; CP->argcount = 1; @@ -415,19 +415,19 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) LOOKAHEAD (MPEXPR_TYPE_PREFIX); if (! (p->token == TOKEN_OPERATOR - && p->token_op->type == MPEXPR_TYPE_OPENPAREN)) + && p->token_op->type == MPEXPR_TYPE_OPENPAREN)) ERROR ("expected open paren for function", MPEXPR_RESULT_PARSE_ERROR); TRACE (printf ("open paren for function \"%s\"\n", CP->op->name)); if ((CP->op->type & MPEXPR_TYPE_MASK_ARGCOUNT) == MPEXPR_TYPE_NARY(0)) { - LOOKAHEAD (0); - if (! (p->token == TOKEN_OPERATOR - && p->token_op->type == MPEXPR_TYPE_CLOSEPAREN)) - ERROR ("expected close paren for 0ary function", - MPEXPR_RESULT_PARSE_ERROR); - goto apply_control_lookahead; + LOOKAHEAD (0); + if (! (p->token == TOKEN_OPERATOR + && p->token_op->type == MPEXPR_TYPE_CLOSEPAREN)) + ERROR ("expected close paren for 0ary function", + MPEXPR_RESULT_PARSE_ERROR); + goto apply_control_lookahead; } goto another_expr_lookahead; @@ -455,51 +455,51 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) || ((tprec) == (cprec) && ! ((ttype) & MPEXPR_TYPE_RIGHTASSOC))) if (PRECEDENCE_TEST_REDUCE (p->token_op->precedence, CP->op->precedence, - p->token_op->type, CP->op->type)) + p->token_op->type, CP->op->type)) { - TRACE (printf ("defer operator: %s (prec %d vs %d, type 0x%X)\n", - p->token_op->name, - p->token_op->precedence, CP->op->precedence, - p->token_op->type)); - goto apply_control; + TRACE (printf ("defer operator: %s (prec %d vs %d, type 0x%X)\n", + p->token_op->name, + p->token_op->precedence, CP->op->precedence, + p->token_op->type)); + goto apply_control; } /* An argsep is a binary operator, but is never pushed on the control stack, it just accumulates an extra argument for a function. */ if (p->token_op->type == MPEXPR_TYPE_ARGSEP) { - if (CP->op->precedence != 0) - ERROR ("ARGSEP not in a function call", MPEXPR_RESULT_PARSE_ERROR); + if (CP->op->precedence != 0) + ERROR ("ARGSEP not in a function call", MPEXPR_RESULT_PARSE_ERROR); - TRACE (printf ("argsep for function \"%s\"(%d)\n", - CP->op->name, CP->argcount)); + TRACE (printf ("argsep for function \"%s\"(%d)\n", + CP->op->name, CP->argcount)); #define IS_PAIRWISE(type) \ - (((type) & (MPEXPR_TYPE_MASK_ARGCOUNT | MPEXPR_TYPE_PAIRWISE)) \ - == (MPEXPR_TYPE_BINARY | MPEXPR_TYPE_PAIRWISE)) - - if (IS_PAIRWISE (CP->op->type) && CP->argcount >= 2) - { - TRACE (printf (" will reduce pairwise now\n")); - CP->argcount--; - CONTROL_PUSH (CP->op, 2); - goto apply_control; - } - - CP->argcount++; - goto another_expr_lookahead; + (((type) & (MPEXPR_TYPE_MASK_ARGCOUNT | MPEXPR_TYPE_PAIRWISE)) \ + == (MPEXPR_TYPE_BINARY | MPEXPR_TYPE_PAIRWISE)) + + if (IS_PAIRWISE (CP->op->type) && CP->argcount >= 2) + { + TRACE (printf (" will reduce pairwise now\n")); + CP->argcount--; + CONTROL_PUSH (CP->op, 2); + goto apply_control; + } + + CP->argcount++; + goto another_expr_lookahead; } switch (p->token_op->type & MPEXPR_TYPE_MASK_ARGCOUNT) { case MPEXPR_TYPE_NARY(1): /* Postfix unary operators can always be applied immediately. The - easiest way to do this is just push it on the control stack and go - to the normal control stack reduction code. */ + easiest way to do this is just push it on the control stack and go + to the normal control stack reduction code. */ TRACE (printf ("postfix unary operator: %s\n", p->token_op->name)); if (p->token_op->type & MPEXPR_TYPE_PREFIX) - ERROR ("prefix unary operator used postfix", - MPEXPR_RESULT_PARSE_ERROR); + ERROR ("prefix unary operator used postfix", + MPEXPR_RESULT_PARSE_ERROR); CONTROL_PUSH (p->token_op, 1); goto apply_control_lookahead; @@ -513,7 +513,7 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) } TRACE (printf ("unrecognised operator \"%s\" type: 0x%X", - CP->op->name, CP->op->type)); + CP->op->name, CP->op->type)); ERROR ("", MPEXPR_RESULT_PARSE_ERROR); break; @@ -534,10 +534,10 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) otherwise recognise the various uses of SP as common subexpressions. */ TRACE (printf ("apply control: nested %d, \"%s\" 0x%X, %d args\n", - p->control_top, CP->op->name, CP->op->type, CP->argcount)); + p->control_top, CP->op->name, CP->op->type, CP->argcount)); TRACE (printf ("apply 0x%X-ary\n", - CP->op->type & MPEXPR_TYPE_MASK_ARGCOUNT)); + CP->op->type & MPEXPR_TYPE_MASK_ARGCOUNT)); switch (CP->op->type & MPEXPR_TYPE_MASK_ARGCOUNT) { case MPEXPR_TYPE_NARY(0): { @@ -547,14 +547,14 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) sp = SP; switch (CP->op->type & MPEXPR_TYPE_MASK_ARGSTYLE) { case 0: - (* (mpexpr_fun_0ary_t) CP->op->fun) (sp); - break; + (* (mpexpr_fun_0ary_t) CP->op->fun) (sp); + break; case MPEXPR_TYPE_RESULT_INT: - (*p->mpX_set_si) (sp, (long) (* (mpexpr_fun_i_0ary_t) CP->op->fun) ()); - break; + (*p->mpX_set_si) (sp, (long) (* (mpexpr_fun_i_0ary_t) CP->op->fun) ()); + break; default: - ERROR ("unrecognised 0ary argument calling style", - MPEXPR_RESULT_BAD_TABLE); + ERROR ("unrecognised 0ary argument calling style", + MPEXPR_RESULT_BAD_TABLE); } } break; @@ -567,63 +567,63 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) switch (CP->op->type & MPEXPR_TYPE_MASK_SPECIAL) { case 0: - /* not a special */ - break; + /* not a special */ + break; case MPEXPR_TYPE_DONE & MPEXPR_TYPE_MASK_SPECIAL: - TRACE (printf ("special done\n")); - goto done; + TRACE (printf ("special done\n")); + goto done; case MPEXPR_TYPE_LOGICAL_NOT & MPEXPR_TYPE_MASK_SPECIAL: - TRACE (printf ("special logical not\n")); - (*p->mpX_set_si) - (sp, (long) ((* (mpexpr_fun_i_unary_t) CP->op->fun) (sp) == 0)); - goto apply_control_done; + TRACE (printf ("special logical not\n")); + (*p->mpX_set_si) + (sp, (long) ((* (mpexpr_fun_i_unary_t) CP->op->fun) (sp) == 0)); + goto apply_control_done; case MPEXPR_TYPE_CLOSEPAREN & MPEXPR_TYPE_MASK_SPECIAL: - CONTROL_POP (); - if (CP->op->type == MPEXPR_TYPE_OPENPAREN) - { - TRACE (printf ("close paren matching open paren\n")); - CONTROL_POP (); - goto another_operator; - } - if (CP->op->precedence == 0) - { - TRACE (printf ("close paren for function\n")); - goto apply_control; - } - ERROR ("unexpected close paren", MPEXPR_RESULT_PARSE_ERROR); + CONTROL_POP (); + if (CP->op->type == MPEXPR_TYPE_OPENPAREN) + { + TRACE (printf ("close paren matching open paren\n")); + CONTROL_POP (); + goto another_operator; + } + if (CP->op->precedence == 0) + { + TRACE (printf ("close paren for function\n")); + goto apply_control; + } + ERROR ("unexpected close paren", MPEXPR_RESULT_PARSE_ERROR); default: - TRACE (printf ("unrecognised special unary operator 0x%X", - CP->op->type & MPEXPR_TYPE_MASK_SPECIAL)); - ERROR ("", MPEXPR_RESULT_BAD_TABLE); + TRACE (printf ("unrecognised special unary operator 0x%X", + CP->op->type & MPEXPR_TYPE_MASK_SPECIAL)); + ERROR ("", MPEXPR_RESULT_BAD_TABLE); } switch (CP->op->type & MPEXPR_TYPE_MASK_ARGSTYLE) { case 0: - (* (mpexpr_fun_unary_t) CP->op->fun) (sp, sp); - break; + (* (mpexpr_fun_unary_t) CP->op->fun) (sp, sp); + break; case MPEXPR_TYPE_LAST_UI: - CHECK_UI (sp); - (* (mpexpr_fun_unary_ui_t) CP->op->fun) - (sp, (*p->mpX_get_ui) (sp)); - break; + CHECK_UI (sp); + (* (mpexpr_fun_unary_ui_t) CP->op->fun) + (sp, (*p->mpX_get_ui) (sp)); + break; case MPEXPR_TYPE_RESULT_INT: - (*p->mpX_set_si) - (sp, (long) (* (mpexpr_fun_i_unary_t) CP->op->fun) (sp)); - break; + (*p->mpX_set_si) + (sp, (long) (* (mpexpr_fun_i_unary_t) CP->op->fun) (sp)); + break; case MPEXPR_TYPE_RESULT_INT | MPEXPR_TYPE_LAST_UI: - CHECK_UI (sp); - (*p->mpX_set_si) - (sp, - (long) (* (mpexpr_fun_i_unary_ui_t) CP->op->fun) - ((*p->mpX_get_ui) (sp))); - break; + CHECK_UI (sp); + (*p->mpX_set_si) + (sp, + (long) (* (mpexpr_fun_i_unary_ui_t) CP->op->fun) + ((*p->mpX_get_ui) (sp))); + break; default: - ERROR ("unrecognised unary argument calling style", - MPEXPR_RESULT_BAD_TABLE); + ERROR ("unrecognised unary argument calling style", + MPEXPR_RESULT_BAD_TABLE); } } break; @@ -634,113 +634,113 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) /* pairwise functions are allowed to have just one argument */ if ((CP->op->type & MPEXPR_TYPE_PAIRWISE) - && CP->op->precedence == 0 - && CP->argcount == 1) - goto apply_control_done; + && CP->op->precedence == 0 + && CP->argcount == 1) + goto apply_control_done; CHECK_ARGCOUNT ("binary", 2); DATA_POP (1); sp = SP; TRACE (MPX_TRACE ("lhs", sp); - MPX_TRACE ("rhs", sp+1)); + MPX_TRACE ("rhs", sp+1)); if (CP->op->type & MPEXPR_TYPE_MASK_CMP) - { - int type = CP->op->type; - int cmp = (* (mpexpr_fun_i_binary_t) CP->op->fun) - (sp, sp+1); - (*p->mpX_set_si) - (sp, - (long) - (( (cmp < 0) & ((type & MPEXPR_TYPE_MASK_CMP_LT) != 0)) - | ((cmp == 0) & ((type & MPEXPR_TYPE_MASK_CMP_EQ) != 0)) - | ((cmp > 0) & ((type & MPEXPR_TYPE_MASK_CMP_GT) != 0)))); - goto apply_control_done; - } + { + int type = CP->op->type; + int cmp = (* (mpexpr_fun_i_binary_t) CP->op->fun) + (sp, sp+1); + (*p->mpX_set_si) + (sp, + (long) + (( (cmp < 0) & ((type & MPEXPR_TYPE_MASK_CMP_LT) != 0)) + | ((cmp == 0) & ((type & MPEXPR_TYPE_MASK_CMP_EQ) != 0)) + | ((cmp > 0) & ((type & MPEXPR_TYPE_MASK_CMP_GT) != 0)))); + goto apply_control_done; + } switch (CP->op->type & MPEXPR_TYPE_MASK_SPECIAL) { case 0: - /* not a special */ - break; + /* not a special */ + break; case MPEXPR_TYPE_QUESTION & MPEXPR_TYPE_MASK_SPECIAL: - ERROR ("'?' without ':'", MPEXPR_RESULT_PARSE_ERROR); + ERROR ("'?' without ':'", MPEXPR_RESULT_PARSE_ERROR); case MPEXPR_TYPE_COLON & MPEXPR_TYPE_MASK_SPECIAL: - TRACE (printf ("special colon\n")); - CONTROL_POP (); - if (CP->op->type != MPEXPR_TYPE_QUESTION) - ERROR ("':' without '?'", MPEXPR_RESULT_PARSE_ERROR); - - CP->argcount--; - DATA_POP (1); - sp--; - TRACE (MPX_TRACE ("query", sp); - MPX_TRACE ("true", sp+1); - MPX_TRACE ("false", sp+2)); - (*p->mpX_set) - (sp, (* (mpexpr_fun_i_unary_t) CP->op->fun) (sp) - ? sp+1 : sp+2); - goto apply_control_done; + TRACE (printf ("special colon\n")); + CONTROL_POP (); + if (CP->op->type != MPEXPR_TYPE_QUESTION) + ERROR ("':' without '?'", MPEXPR_RESULT_PARSE_ERROR); + + CP->argcount--; + DATA_POP (1); + sp--; + TRACE (MPX_TRACE ("query", sp); + MPX_TRACE ("true", sp+1); + MPX_TRACE ("false", sp+2)); + (*p->mpX_set) + (sp, (* (mpexpr_fun_i_unary_t) CP->op->fun) (sp) + ? sp+1 : sp+2); + goto apply_control_done; case MPEXPR_TYPE_LOGICAL_AND & MPEXPR_TYPE_MASK_SPECIAL: - TRACE (printf ("special logical and\n")); - (*p->mpX_set_si) - (sp, - (long) - ((* (mpexpr_fun_i_unary_t) CP->op->fun) (sp) - && (* (mpexpr_fun_i_unary_t) CP->op->fun) (sp+1))); - goto apply_control_done; + TRACE (printf ("special logical and\n")); + (*p->mpX_set_si) + (sp, + (long) + ((* (mpexpr_fun_i_unary_t) CP->op->fun) (sp) + && (* (mpexpr_fun_i_unary_t) CP->op->fun) (sp+1))); + goto apply_control_done; case MPEXPR_TYPE_LOGICAL_OR & MPEXPR_TYPE_MASK_SPECIAL: - TRACE (printf ("special logical and\n")); - (*p->mpX_set_si) - (sp, - (long) - ((* (mpexpr_fun_i_unary_t) CP->op->fun) (sp) - || (* (mpexpr_fun_i_unary_t) CP->op->fun) (sp+1))); - goto apply_control_done; + TRACE (printf ("special logical and\n")); + (*p->mpX_set_si) + (sp, + (long) + ((* (mpexpr_fun_i_unary_t) CP->op->fun) (sp) + || (* (mpexpr_fun_i_unary_t) CP->op->fun) (sp+1))); + goto apply_control_done; case MPEXPR_TYPE_MAX & MPEXPR_TYPE_MASK_SPECIAL: - TRACE (printf ("special max\n")); - if ((* (mpexpr_fun_i_binary_t) CP->op->fun) (sp, sp+1) < 0) - (*p->mpX_swap) (sp, sp+1); - goto apply_control_done; + TRACE (printf ("special max\n")); + if ((* (mpexpr_fun_i_binary_t) CP->op->fun) (sp, sp+1) < 0) + (*p->mpX_swap) (sp, sp+1); + goto apply_control_done; case MPEXPR_TYPE_MIN & MPEXPR_TYPE_MASK_SPECIAL: - TRACE (printf ("special min\n")); - if ((* (mpexpr_fun_i_binary_t) CP->op->fun) (sp, sp+1) > 0) - (*p->mpX_swap) (sp, sp+1); - goto apply_control_done; + TRACE (printf ("special min\n")); + if ((* (mpexpr_fun_i_binary_t) CP->op->fun) (sp, sp+1) > 0) + (*p->mpX_swap) (sp, sp+1); + goto apply_control_done; default: - ERROR ("unrecognised special binary operator", - MPEXPR_RESULT_BAD_TABLE); + ERROR ("unrecognised special binary operator", + MPEXPR_RESULT_BAD_TABLE); } switch (CP->op->type & MPEXPR_TYPE_MASK_ARGSTYLE) { case 0: - (* (mpexpr_fun_binary_t) CP->op->fun) (sp, sp, sp+1); - break; + (* (mpexpr_fun_binary_t) CP->op->fun) (sp, sp, sp+1); + break; case MPEXPR_TYPE_LAST_UI: - CHECK_UI (sp+1); - (* (mpexpr_fun_binary_ui_t) CP->op->fun) - (sp, sp, (*p->mpX_get_ui) (sp+1)); - break; + CHECK_UI (sp+1); + (* (mpexpr_fun_binary_ui_t) CP->op->fun) + (sp, sp, (*p->mpX_get_ui) (sp+1)); + break; case MPEXPR_TYPE_RESULT_INT: - (*p->mpX_set_si) - (sp, - (long) (* (mpexpr_fun_i_binary_t) CP->op->fun) (sp, sp+1)); - break; + (*p->mpX_set_si) + (sp, + (long) (* (mpexpr_fun_i_binary_t) CP->op->fun) (sp, sp+1)); + break; case MPEXPR_TYPE_LAST_UI | MPEXPR_TYPE_RESULT_INT: - CHECK_UI (sp+1); - (*p->mpX_set_si) - (sp, - (long) (* (mpexpr_fun_i_binary_ui_t) CP->op->fun) - (sp, (*p->mpX_get_ui) (sp+1))); - break; + CHECK_UI (sp+1); + (*p->mpX_set_si) + (sp, + (long) (* (mpexpr_fun_i_binary_ui_t) CP->op->fun) + (sp, (*p->mpX_get_ui) (sp+1))); + break; default: - ERROR ("unrecognised binary argument calling style", - MPEXPR_RESULT_BAD_TABLE); + ERROR ("unrecognised binary argument calling style", + MPEXPR_RESULT_BAD_TABLE); } } break; @@ -753,34 +753,34 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) DATA_POP (2); sp = SP; TRACE (MPX_TRACE ("arg1", sp); - MPX_TRACE ("arg2", sp+1); - MPX_TRACE ("arg3", sp+1)); + MPX_TRACE ("arg2", sp+1); + MPX_TRACE ("arg3", sp+1)); switch (CP->op->type & MPEXPR_TYPE_MASK_ARGSTYLE) { case 0: - (* (mpexpr_fun_ternary_t) CP->op->fun) (sp, sp, sp+1, sp+2); - break; + (* (mpexpr_fun_ternary_t) CP->op->fun) (sp, sp, sp+1, sp+2); + break; case MPEXPR_TYPE_LAST_UI: - CHECK_UI (sp+2); - (* (mpexpr_fun_ternary_ui_t) CP->op->fun) - (sp, sp, sp+1, (*p->mpX_get_ui) (sp+2)); - break; + CHECK_UI (sp+2); + (* (mpexpr_fun_ternary_ui_t) CP->op->fun) + (sp, sp, sp+1, (*p->mpX_get_ui) (sp+2)); + break; case MPEXPR_TYPE_RESULT_INT: - (*p->mpX_set_si) - (sp, - (long) (* (mpexpr_fun_i_ternary_t) CP->op->fun) - (sp, sp+1, sp+2)); - break; + (*p->mpX_set_si) + (sp, + (long) (* (mpexpr_fun_i_ternary_t) CP->op->fun) + (sp, sp+1, sp+2)); + break; case MPEXPR_TYPE_LAST_UI | MPEXPR_TYPE_RESULT_INT: - CHECK_UI (sp+2); - (*p->mpX_set_si) - (sp, - (long) (* (mpexpr_fun_i_ternary_ui_t) CP->op->fun) - (sp, sp+1, (*p->mpX_get_ui) (sp+2))); - break; + CHECK_UI (sp+2); + (*p->mpX_set_si) + (sp, + (long) (* (mpexpr_fun_i_ternary_ui_t) CP->op->fun) + (sp, sp+1, (*p->mpX_get_ui) (sp+2))); + break; default: - ERROR ("unrecognised binary argument calling style", - MPEXPR_RESULT_BAD_TABLE); + ERROR ("unrecognised binary argument calling style", + MPEXPR_RESULT_BAD_TABLE); } } break; @@ -799,20 +799,20 @@ mpexpr_evaluate (struct mpexpr_parse_t *p) if (p->error_code == MPEXPR_RESULT_OK) { if (p->data_top != 0) - { - TRACE (printf ("data stack want top at 0, got %d\n", p->data_top)); - p->error_code = MPEXPR_RESULT_PARSE_ERROR; - } + { + TRACE (printf ("data stack want top at 0, got %d\n", p->data_top)); + p->error_code = MPEXPR_RESULT_PARSE_ERROR; + } else - (*p->mpX_set_or_swap) (p->res, SP); + (*p->mpX_set_or_swap) (p->res, SP); } { int i; for (i = 0; i < p->data_inited; i++) { - TRACE (printf ("clear %d\n", i)); - (*p->mpX_clear) (p->data_stack+i); + TRACE (printf ("clear %d\n", i)); + (*p->mpX_clear) (p->data_stack+i); } } diff --git a/demos/expr/expr.h b/demos/expr/expr.h index a679f179d..c3525b61e 100644 --- a/demos/expr/expr.h +++ b/demos/expr/expr.h @@ -28,7 +28,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #define MPEXPR_RESULT_NOT_UI 4 -/* basic types */ +/* basic types */ #define MPEXPR_TYPE_NARY(n) ((n) * 0x0100) #define MPEXPR_TYPE_MASK_ARGCOUNT MPEXPR_TYPE_NARY(0xF) #define MPEXPR_TYPE_0ARY MPEXPR_TYPE_NARY(0) @@ -84,11 +84,11 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #define MPEXPR_TYPE_MASK_CMP_EQ 0x002 #define MPEXPR_TYPE_MASK_CMP_GT 0x004 #define MPEXPR_TYPE_CMP_LT (MPEXPR_TYPE_BINARY | MPEXPR_TYPE_MASK_CMP \ - | MPEXPR_TYPE_MASK_CMP_LT) + | MPEXPR_TYPE_MASK_CMP_LT) #define MPEXPR_TYPE_CMP_EQ (MPEXPR_TYPE_BINARY | MPEXPR_TYPE_MASK_CMP \ - | MPEXPR_TYPE_MASK_CMP_EQ) + | MPEXPR_TYPE_MASK_CMP_EQ) #define MPEXPR_TYPE_CMP_GT (MPEXPR_TYPE_BINARY | MPEXPR_TYPE_MASK_CMP \ - | MPEXPR_TYPE_MASK_CMP_GT) + | MPEXPR_TYPE_MASK_CMP_GT) #define MPEXPR_TYPE_CMP_LE (MPEXPR_TYPE_CMP_LT | MPEXPR_TYPE_MASK_CMP_EQ) #define MPEXPR_TYPE_CMP_NE (MPEXPR_TYPE_CMP_LT | MPEXPR_TYPE_MASK_CMP_GT) #define MPEXPR_TYPE_CMP_GE (MPEXPR_TYPE_CMP_GT | MPEXPR_TYPE_MASK_CMP_EQ) @@ -109,21 +109,21 @@ struct mpexpr_operator_t { int mpf_expr_a __GMP_PROTO ((__gmp_const struct mpexpr_operator_t *table, - mpf_ptr res, int base, unsigned long prec, - __gmp_const char *e, size_t elen, - mpf_srcptr var[26])); + mpf_ptr res, int base, unsigned long prec, + __gmp_const char *e, size_t elen, + mpf_srcptr var[26])); int mpf_expr __GMP_PROTO ((mpf_ptr res, int base, __gmp_const char *e, ...)); int mpq_expr_a __GMP_PROTO ((__gmp_const struct mpexpr_operator_t *table, - mpq_ptr res, int base, - __gmp_const char *e, size_t elen, - mpq_srcptr var[26])); + mpq_ptr res, int base, + __gmp_const char *e, size_t elen, + mpq_srcptr var[26])); int mpq_expr __GMP_PROTO ((mpq_ptr res, int base, __gmp_const char *e, ...)); int mpz_expr_a __GMP_PROTO ((__gmp_const struct mpexpr_operator_t *table, - mpz_ptr res, int base, - __gmp_const char *e, size_t elen, - mpz_srcptr var[26])); + mpz_ptr res, int base, + __gmp_const char *e, size_t elen, + mpz_srcptr var[26])); int mpz_expr __GMP_PROTO ((mpz_ptr res, int base, __gmp_const char *e, ...)); #endif diff --git a/demos/expr/exprf.c b/demos/expr/exprf.c index 584c19d92..c67ee5178 100644 --- a/demos/expr/exprf.c +++ b/demos/expr/exprf.c @@ -38,7 +38,7 @@ static __gmp_const struct mpexpr_operator_t _mpf_expr_standard_table[] = { { "**", (mpexpr_fun_t) mpf_pow_ui, MPEXPR_TYPE_BINARY_UI | MPEXPR_TYPE_RIGHTASSOC, 220 }, - + { "!", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_NOT | MPEXPR_TYPE_PREFIX, 210 }, { "-", (mpexpr_fun_t) mpf_neg, @@ -123,5 +123,5 @@ mpf_expr (va_alist) return ret; return mpf_expr_a (mpf_expr_standard_table, res, base, - mpf_get_prec (res), e, strlen(e), var); + mpf_get_prec (res), e, strlen(e), var); } diff --git a/demos/expr/exprq.c b/demos/expr/exprq.c index f648516f2..af91b0016 100644 --- a/demos/expr/exprq.c +++ b/demos/expr/exprq.c @@ -76,7 +76,7 @@ static __gmp_const struct mpexpr_operator_t _mpq_expr_standard_table[] = { { "**", (mpexpr_fun_t) e_mpq_pow_ui, MPEXPR_TYPE_BINARY_UI | MPEXPR_TYPE_RIGHTASSOC, 220 }, - + { "!", (mpexpr_fun_t) e_mpq_sgn, MPEXPR_TYPE_LOGICAL_NOT | MPEXPR_TYPE_PREFIX, 210 }, { "-", (mpexpr_fun_t) mpq_neg, diff --git a/demos/expr/exprv.c b/demos/expr/exprv.c index a01b47bdb..b53682eec 100644 --- a/demos/expr/exprv.c +++ b/demos/expr/exprv.c @@ -18,7 +18,6 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ - #include <stdio.h> #include "gmp.h" #include "expr-impl.h" @@ -34,9 +33,9 @@ mpexpr_va_to_var (void *var[], va_list ap) { v = va_arg (ap, void *); if (v == NULL) - break; + break; if (i >= MPEXPR_VARIABLES) - return MPEXPR_RESULT_BAD_VARIABLE; + return MPEXPR_RESULT_BAD_VARIABLE; var[i++] = v; } diff --git a/demos/expr/exprz.c b/demos/expr/exprz.c index 33196001b..7c01b9dc5 100644 --- a/demos/expr/exprz.c +++ b/demos/expr/exprz.c @@ -90,8 +90,8 @@ static __gmp_const struct mpexpr_operator_t _mpz_expr_standard_table[] = { { "**", (mpexpr_fun_t) mpz_pow_ui, MPEXPR_TYPE_BINARY_UI | MPEXPR_TYPE_RIGHTASSOC, 220 }, - - { "~", (mpexpr_fun_t) mpz_com, + + { "~", (mpexpr_fun_t) mpz_com, MPEXPR_TYPE_UNARY | MPEXPR_TYPE_PREFIX, 210 }, { "!", (mpexpr_fun_t) e_mpz_sgn, MPEXPR_TYPE_LOGICAL_NOT | MPEXPR_TYPE_PREFIX, 210 }, @@ -141,18 +141,18 @@ static __gmp_const struct mpexpr_operator_t _mpz_expr_standard_table[] = { { "fib", (mpexpr_fun_t) mpz_fib_ui, MPEXPR_TYPE_UNARY_UI }, { "fac", (mpexpr_fun_t) mpz_fac_ui, MPEXPR_TYPE_UNARY_UI }, { "gcd", (mpexpr_fun_t) mpz_gcd, MPEXPR_TYPE_BINARY - | MPEXPR_TYPE_PAIRWISE }, + | MPEXPR_TYPE_PAIRWISE }, { "hamdist", (mpexpr_fun_t) e_mpz_hamdist, MPEXPR_TYPE_BINARY }, { "invert", (mpexpr_fun_t) mpz_invert, MPEXPR_TYPE_BINARY }, { "jacobi", (mpexpr_fun_t) mpz_jacobi, MPEXPR_TYPE_I_BINARY }, { "kronecker", (mpexpr_fun_t) mpz_kronecker, MPEXPR_TYPE_I_BINARY }, { "lcm", (mpexpr_fun_t) mpz_lcm, MPEXPR_TYPE_BINARY - | MPEXPR_TYPE_PAIRWISE }, + | MPEXPR_TYPE_PAIRWISE }, { "lucnum", (mpexpr_fun_t) mpz_lucnum_ui, MPEXPR_TYPE_UNARY_UI }, { "max", (mpexpr_fun_t) mpz_cmp, MPEXPR_TYPE_MAX - | MPEXPR_TYPE_PAIRWISE }, + | MPEXPR_TYPE_PAIRWISE }, { "min", (mpexpr_fun_t) mpz_cmp, MPEXPR_TYPE_MIN - | MPEXPR_TYPE_PAIRWISE }, + | MPEXPR_TYPE_PAIRWISE }, { "nextprime", (mpexpr_fun_t) mpz_nextprime, MPEXPR_TYPE_UNARY }, { "odd_p", (mpexpr_fun_t) e_mpz_odd_p, MPEXPR_TYPE_I_UNARY }, { "perfect_power_p", (mpexpr_fun_t)mpz_perfect_power_p, MPEXPR_TYPE_I_UNARY}, @@ -208,4 +208,3 @@ mpz_expr (va_alist) return mpz_expr_a (mpz_expr_standard_table, res, base, e, strlen(e), var); } - diff --git a/demos/perl/GMP.xs b/demos/perl/GMP.xs index c9e4a79f3..2282c8928 100644 --- a/demos/perl/GMP.xs +++ b/demos/perl/GMP.xs @@ -63,7 +63,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. #define NDEBUG /* Change this to "#define TRACE(x) x" for some diagnostics. */ -#define TRACE(x) +#define TRACE(x) #include <assert.h> diff --git a/demos/perl/test.pl b/demos/perl/test.pl index 9edb08f0e..40a903378 100644 --- a/demos/perl/test.pl +++ b/demos/perl/test.pl @@ -781,7 +781,7 @@ foreach my $i ([ 1, 19, 1 ], ok (&$fun (mpz($$i[0]), $$i[1]) == $$i[2]); ok (&$fun (mpz($$i[0]), mpz($$i[1])) == $$i[2]); } -} +} #------------------------------------------------------------------------------ # GMP::Mpz::lcm @@ -1677,7 +1677,7 @@ ok (floor(mpf(7.5)) == 7.0); { my $old_prec = get_default_prec(); set_default_prec(128); - + ok ( mpf_eq (mpz("0x10000000000000001"), mpz("0x10000000000000002"), 1)); ok (! mpf_eq (mpz("0x11"), mpz("0x12"), 128)); @@ -1789,7 +1789,7 @@ ok (trunc(mpf(7.5)) == 7.0); { my $r = randstate(); my $z = mpz_urandomm($r, mpz(3)**100); ok (UNIVERSAL::isa($z,"GMP::Mpz")); } - + #------------------------------------------------------------------------------ # GMP::Rand::mpz_urandomb_ui @@ -2100,7 +2100,7 @@ ok (via_printf ("%#X", mpq(15,16)) eq '0XF/0X10'); ok (via_printf ("%*.*f", 10, 3, 1.25) eq ' 1.250'); ok (via_printf ("%*.*f", 10, 3, mpf(1.5)) eq ' 1.500'); - + #------------------------------------------------------------------------------ # GMP::sgn diff --git a/demos/perl/test2.pl b/demos/perl/test2.pl index 0f30326ca..645d3cfbb 100644 --- a/demos/perl/test2.pl +++ b/demos/perl/test2.pl @@ -28,14 +28,14 @@ use GMP::Mpz qw(:constants); ok (UNIVERSAL::isa ($a, "GMP::Mpz")); } use GMP::Mpz qw(:noconstants); - + use GMP::Mpq qw(:constants); { my $a = 123; ok (UNIVERSAL::isa ($a, "GMP::Mpq")); } use GMP::Mpq qw(:noconstants); - + use GMP::Mpf qw(:constants); { my $a = 123; diff --git a/doc/configuration b/doc/configuration index aae681b99..fbd3b960d 100644 --- a/doc/configuration +++ b/doc/configuration @@ -278,19 +278,19 @@ During development: Input files Tool Output files --------------------------------------------------------- - + aclocal $prefix/share/aclocal*/*.m4 ----------------> aclocal.m4 - + configure.in \ autoconf aclocal.m4 / -----------------------------> configure - + */Makefile.am \ automake configure.in | ----------------------------> Makefile.in aclocal.m4 / - + configure.in \ autoheader aclocal.m4 / -----------------------------> config.in diff --git a/gen-bases.c b/gen-bases.c index 55bd7f190..31895e8b2 100644 --- a/gen-bases.c +++ b/gen-bases.c @@ -178,4 +178,3 @@ main (int argc, char **argv) return 0; } - diff --git a/mpf/get_ui.c b/mpf/get_ui.c index 147467ce1..0acaf94a8 100644 --- a/mpf/get_ui.c +++ b/mpf/get_ui.c @@ -17,7 +17,6 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ - #include "gmp.h" #include "gmp-impl.h" diff --git a/mpf/int_p.c b/mpf/int_p.c index f966c1fe6..d43dcf813 100644 --- a/mpf/int_p.c +++ b/mpf/int_p.c @@ -18,7 +18,6 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ - #include "gmp.h" #include "gmp-impl.h" diff --git a/mpf/reldiff.c b/mpf/reldiff.c index 631daf84d..f9e40b66e 100644 --- a/mpf/reldiff.c +++ b/mpf/reldiff.c @@ -52,4 +52,3 @@ mpf_reldiff (mpf_t rdiff, mpf_srcptr x, mpf_srcptr y) TMP_FREE; } } - diff --git a/mpn/Makeasm.am b/mpn/Makeasm.am index a927975a8..2e736c909 100644 --- a/mpn/Makeasm.am +++ b/mpn/Makeasm.am @@ -16,7 +16,7 @@ # License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ +# along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. # COMPILE minus CC. diff --git a/mpn/generic/add_1.c b/mpn/generic/add_1.c index 252cec3a5..2d3fa76c2 100644 --- a/mpn/generic/add_1.c +++ b/mpn/generic/add_1.c @@ -17,7 +17,6 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ - #define __GMP_FORCE_mpn_add_1 1 #include "gmp.h" diff --git a/mpn/generic/divis.c b/mpn/generic/divis.c index ae19e62c4..b05ecd8a7 100644 --- a/mpn/generic/divis.c +++ b/mpn/generic/divis.c @@ -131,7 +131,7 @@ mpn_divisible_p (mp_srcptr ap, mp_size_t asize, unsigned twos; count_trailing_zeros (twos, dlow); dlow = (dlow >> twos) | (dsecond << (GMP_NUMB_BITS-twos)); - ASSERT_LIMB (dlow); + ASSERT_LIMB (dlow); return MPN_MOD_OR_MODEXACT_1_ODD (ap, asize, dlow) == 0; } } diff --git a/mpn/generic/dump.c b/mpn/generic/dump.c index 67efc2589..38309996c 100644 --- a/mpn/generic/dump.c +++ b/mpn/generic/dump.c @@ -20,7 +20,6 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ - #include <stdio.h> #include "gmp.h" #include "gmp-impl.h" diff --git a/mpn/generic/mode1o.c b/mpn/generic/mode1o.c index ca03f3488..6f4398c06 100644 --- a/mpn/generic/mode1o.c +++ b/mpn/generic/mode1o.c @@ -21,7 +21,6 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ - #include "gmp.h" #include "gmp-impl.h" #include "longlong.h" diff --git a/mpn/generic/popham.c b/mpn/generic/popham.c index 19ba8329d..be7c52503 100644 --- a/mpn/generic/popham.c +++ b/mpn/generic/popham.c @@ -42,7 +42,7 @@ FNAME (mp_srcptr up, mp_size_t i; ASSERT (n >= 1); /* Actually, this code handles any n, but some - assembly implementations does not. */ + assembly implementations do not. */ for (i = n >> 2; i != 0; i--) { diff --git a/mpn/generic/sub_1.c b/mpn/generic/sub_1.c index 5fd18652f..4ed2eabcc 100644 --- a/mpn/generic/sub_1.c +++ b/mpn/generic/sub_1.c @@ -17,7 +17,6 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ - #define __GMP_FORCE_mpn_sub_1 1 #include "gmp.h" diff --git a/mpn/ia64/README b/mpn/ia64/README index 1f871cb63..9252271ab 100644 --- a/mpn/ia64/README +++ b/mpn/ia64/README @@ -42,7 +42,7 @@ at the end of a bundle, but can be put between operations within some bundle types too. The Itanium 1 and Itanium 2 implementations can under ideal conditions -execute two bundles per cycle. The Itanium 2 allows 4 of these instructions +execute two bundles per cycle. The Itanium 1 allows 4 of these instructions to do integer operations, while the Itanium 2 allows all 6 to be integer operations. diff --git a/mpn/x86/k6/cross.pl b/mpn/x86/k6/cross.pl index 4cc807d1e..cf476d603 100755 --- a/mpn/x86/k6/cross.pl +++ b/mpn/x86/k6/cross.pl @@ -72,7 +72,7 @@ sub disassemble { $align = 8 } } - + if (/^[ \t]*([0-9a-f]*):[ \t]*([0-9a-f]+)[ \t]+([0-9a-f]+)[ \t]+([0-9a-f]+)/) { ($addr,$b1,$b2,$b3) = ($1,$2,$3,$4); diff --git a/mpn/x86/pentium4/mmx/popham.asm b/mpn/x86/pentium4/mmx/popham.asm index 3fcf7f096..eab599586 100644 --- a/mpn/x86/pentium4/mmx/popham.asm +++ b/mpn/x86/pentium4/mmx/popham.asm @@ -22,12 +22,12 @@ include(`../config.m4') C popcount hamdist -C P3 model 9 (Banias) ? ? +C P3 model 9 (Banias) ? ? C P3 model 13 (Dothan) 6 6 C P4 model 0 (Willamette) C P4 model 1 (?) -C P4 model 2 (Northwood) 8 9 -C P4 model 3 (Prescott) 8 9 +C P4 model 2 (Northwood) 8 9 +C P4 model 3 (Prescott) 8 9 C P4 model 4 (Nocona) C unsigned long mpn_popcount (mp_srcptr src, mp_size_t size); diff --git a/mpn/x86/pentium4/sse2/submul_1.asm b/mpn/x86/pentium4/sse2/submul_1.asm index bfebad112..ceb41f2ac 100644 --- a/mpn/x86/pentium4/sse2/submul_1.asm +++ b/mpn/x86/pentium4/sse2/submul_1.asm @@ -18,7 +18,6 @@ dnl dnl You should have received a copy of the GNU Lesser General Public License dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. - include(`../config.m4') diff --git a/mpz/kronzs.c b/mpz/kronzs.c index 1b0473f00..045e5563d 100644 --- a/mpz/kronzs.c +++ b/mpz/kronzs.c @@ -80,5 +80,3 @@ mpz_kronecker_si (mpz_srcptr a, long b) JACOBI_MOD_OR_MODEXACT_1_ODD (result_bit1, a_rem, a_ptr, a_size, b_limb); return mpn_jacobi_base (a_rem, b_limb, result_bit1); } - - diff --git a/mpz/ui_pow_ui.c b/mpz/ui_pow_ui.c index 4449ce63c..4a0f7bd58 100644 --- a/mpz/ui_pow_ui.c +++ b/mpz/ui_pow_ui.c @@ -46,4 +46,3 @@ mpz_ui_pow_ui (mpz_ptr r, unsigned long b, unsigned long e) #endif } } - diff --git a/printf/doprnt.c b/printf/doprnt.c index e05af0174..a6e8c082e 100644 --- a/printf/doprnt.c +++ b/printf/doprnt.c @@ -62,7 +62,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ /* change this to "#define TRACE(x) x" for diagnostics */ -#define TRACE(x) +#define TRACE(x) /* Should be portable, but in any case this is only used under some ASSERTs. */ @@ -132,15 +132,15 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ do { \ if (this_fmt == last_fmt) \ { \ - TRACE (printf ("nothing to flush\n")); \ - ASSERT (va_equal (this_ap, last_ap)); \ + TRACE (printf ("nothing to flush\n")); \ + ASSERT (va_equal (this_ap, last_ap)); \ } \ else \ { \ - ASSERT (*this_fmt == '%'); \ - *this_fmt = '\0'; \ - TRACE (printf ("flush \"%s\"\n", last_fmt)); \ - DOPRNT_FORMAT (last_fmt, last_ap); \ + ASSERT (*this_fmt == '%'); \ + *this_fmt = '\0'; \ + TRACE (printf ("flush \"%s\"\n", last_fmt)); \ + DOPRNT_FORMAT (last_fmt, last_ap); \ } \ } while (0) @@ -151,7 +151,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int __gmp_doprnt (const struct doprnt_funs_t *funs, void *data, - const char *orig_fmt, va_list orig_ap) + const char *orig_fmt, va_list orig_ap) { va_list ap, this_ap, last_ap; size_t alloc_fmt_size; @@ -195,7 +195,7 @@ __gmp_doprnt (const struct doprnt_funs_t *funs, void *data, fmt = strchr (fmt, '%'); if (fmt == NULL) - break; + break; /* this_fmt and this_ap are the current '%' sequence being considered */ this_fmt = fmt; @@ -203,12 +203,12 @@ __gmp_doprnt (const struct doprnt_funs_t *funs, void *data, fmt++; /* skip the '%' */ TRACE (printf ("considering\n"); - printf (" last: \"%s\"\n", last_fmt); - printf (" this: \"%s\"\n", this_fmt)); + printf (" last: \"%s\"\n", last_fmt); + printf (" this: \"%s\"\n", this_fmt)); type = '\0'; value = ¶m.width; - + param.base = 10; param.conv = 0; param.expfmt = "e%c%02d"; @@ -224,379 +224,379 @@ __gmp_doprnt (const struct doprnt_funs_t *funs, void *data, seen_precision = 0; /* This loop parses a single % sequence. "break" from the switch - means continue with this %, "goto next" means the conversion - character has been seen and a new % should be sought. */ + means continue with this %, "goto next" means the conversion + character has been seen and a new % should be sought. */ for (;;) - { - fchar = *fmt++; - if (fchar == '\0') - break; - - switch (fchar) { - - case 'a': - /* %a behaves like %e, but defaults to all significant digits, - and there's no leading zeros on the exponent (which is in - fact bit-based) */ - param.base = 16; - param.expfmt = "p%c%d"; - goto conv_a; - case 'A': - param.base = -16; - param.expfmt = "P%c%d"; - conv_a: - param.conv = DOPRNT_CONV_SCIENTIFIC; - param.exptimes4 = 1; - if (! seen_precision) - param.prec = -1; /* default to all digits */ - param.showbase = DOPRNT_SHOWBASE_YES; - param.showtrailing = 1; - goto floating_a; - - case 'c': - /* Let's assume wchar_t will be promoted to "int" in the call, - the same as char will be. */ - (void) va_arg (ap, int); - goto next; - - case 'd': - case 'i': - case 'u': - integer: - TRACE (printf ("integer, base=%d\n", param.base)); - if (! seen_precision) - param.prec = -1; - switch (type) { - case 'j': - /* Let's assume uintmax_t is the same size as intmax_t. */ + { + fchar = *fmt++; + if (fchar == '\0') + break; + + switch (fchar) { + + case 'a': + /* %a behaves like %e, but defaults to all significant digits, + and there's no leading zeros on the exponent (which is in + fact bit-based) */ + param.base = 16; + param.expfmt = "p%c%d"; + goto conv_a; + case 'A': + param.base = -16; + param.expfmt = "P%c%d"; + conv_a: + param.conv = DOPRNT_CONV_SCIENTIFIC; + param.exptimes4 = 1; + if (! seen_precision) + param.prec = -1; /* default to all digits */ + param.showbase = DOPRNT_SHOWBASE_YES; + param.showtrailing = 1; + goto floating_a; + + case 'c': + /* Let's assume wchar_t will be promoted to "int" in the call, + the same as char will be. */ + (void) va_arg (ap, int); + goto next; + + case 'd': + case 'i': + case 'u': + integer: + TRACE (printf ("integer, base=%d\n", param.base)); + if (! seen_precision) + param.prec = -1; + switch (type) { + case 'j': + /* Let's assume uintmax_t is the same size as intmax_t. */ #if HAVE_INTMAX_T - (void) va_arg (ap, intmax_t); + (void) va_arg (ap, intmax_t); #else - ASSERT_FAIL (intmax_t not available); + ASSERT_FAIL (intmax_t not available); #endif - break; - case 'l': - (void) va_arg (ap, long); - break; - case 'L': + break; + case 'l': + (void) va_arg (ap, long); + break; + case 'L': #if HAVE_LONG_LONG - (void) va_arg (ap, long long); + (void) va_arg (ap, long long); #else - ASSERT_FAIL (long long not available); + ASSERT_FAIL (long long not available); #endif - break; - case 'N': - { - mp_ptr xp; - mp_size_t xsize, abs_xsize; - mpz_t z; - FLUSH (); - xp = va_arg (ap, mp_ptr); - PTR(z) = xp; - xsize = (int) va_arg (ap, mp_size_t); - abs_xsize = ABS (xsize); - MPN_NORMALIZE (xp, abs_xsize); - SIZ(z) = (xsize >= 0 ? abs_xsize : -abs_xsize); - ASSERT_CODE (ALLOC(z) = abs_xsize); - gmp_str = mpz_get_str (NULL, param.base, z); - goto gmp_integer; - } - /* break; */ - case 'q': - /* quad_t is probably the same as long long, but let's treat - it separately just to be sure. Also let's assume u_quad_t - will be the same size as quad_t. */ + break; + case 'N': + { + mp_ptr xp; + mp_size_t xsize, abs_xsize; + mpz_t z; + FLUSH (); + xp = va_arg (ap, mp_ptr); + PTR(z) = xp; + xsize = (int) va_arg (ap, mp_size_t); + abs_xsize = ABS (xsize); + MPN_NORMALIZE (xp, abs_xsize); + SIZ(z) = (xsize >= 0 ? abs_xsize : -abs_xsize); + ASSERT_CODE (ALLOC(z) = abs_xsize); + gmp_str = mpz_get_str (NULL, param.base, z); + goto gmp_integer; + } + /* break; */ + case 'q': + /* quad_t is probably the same as long long, but let's treat + it separately just to be sure. Also let's assume u_quad_t + will be the same size as quad_t. */ #if HAVE_QUAD_T - (void) va_arg (ap, quad_t); + (void) va_arg (ap, quad_t); #else - ASSERT_FAIL (quad_t not available); + ASSERT_FAIL (quad_t not available); #endif - break; - case 'Q': - FLUSH (); - gmp_str = mpq_get_str (NULL, param.base, va_arg(ap, mpq_srcptr)); - goto gmp_integer; - case 't': + break; + case 'Q': + FLUSH (); + gmp_str = mpq_get_str (NULL, param.base, va_arg(ap, mpq_srcptr)); + goto gmp_integer; + case 't': #if HAVE_PTRDIFF_T - (void) va_arg (ap, ptrdiff_t); + (void) va_arg (ap, ptrdiff_t); #else - ASSERT_FAIL (ptrdiff_t not available); + ASSERT_FAIL (ptrdiff_t not available); #endif - break; - case 'z': - (void) va_arg (ap, size_t); - break; - case 'Z': - { - int ret; - FLUSH (); - gmp_str = mpz_get_str (NULL, param.base, - va_arg (ap, mpz_srcptr)); - gmp_integer: - ret = __gmp_doprnt_integer (funs, data, ¶m, gmp_str); - (*__gmp_free_func) (gmp_str, strlen(gmp_str)+1); - DOPRNT_ACCUMULATE (ret); - va_copy (last_ap, ap); - last_fmt = fmt; - } - break; - default: - /* default is an "int", and this includes h=short and hh=char - since they're promoted to int in a function call */ - (void) va_arg (ap, int); - break; - } - goto next; - - case 'E': - param.base = -10; - param.expfmt = "E%c%02d"; - /*FALLTHRU*/ - case 'e': - param.conv = DOPRNT_CONV_SCIENTIFIC; - floating: - if (param.showbase == DOPRNT_SHOWBASE_NONZERO) - { - /* # in %e, %f and %g */ - param.showpoint = 1; - param.showtrailing = 1; - } - floating_a: - switch (type) { - case 'F': - FLUSH (); - DOPRNT_ACCUMULATE (__gmp_doprnt_mpf (funs, data, ¶m, - GMP_DECIMAL_POINT, - va_arg (ap, mpf_srcptr))); - va_copy (last_ap, ap); - last_fmt = fmt; - break; - case 'L': + break; + case 'z': + (void) va_arg (ap, size_t); + break; + case 'Z': + { + int ret; + FLUSH (); + gmp_str = mpz_get_str (NULL, param.base, + va_arg (ap, mpz_srcptr)); + gmp_integer: + ret = __gmp_doprnt_integer (funs, data, ¶m, gmp_str); + (*__gmp_free_func) (gmp_str, strlen(gmp_str)+1); + DOPRNT_ACCUMULATE (ret); + va_copy (last_ap, ap); + last_fmt = fmt; + } + break; + default: + /* default is an "int", and this includes h=short and hh=char + since they're promoted to int in a function call */ + (void) va_arg (ap, int); + break; + } + goto next; + + case 'E': + param.base = -10; + param.expfmt = "E%c%02d"; + /*FALLTHRU*/ + case 'e': + param.conv = DOPRNT_CONV_SCIENTIFIC; + floating: + if (param.showbase == DOPRNT_SHOWBASE_NONZERO) + { + /* # in %e, %f and %g */ + param.showpoint = 1; + param.showtrailing = 1; + } + floating_a: + switch (type) { + case 'F': + FLUSH (); + DOPRNT_ACCUMULATE (__gmp_doprnt_mpf (funs, data, ¶m, + GMP_DECIMAL_POINT, + va_arg (ap, mpf_srcptr))); + va_copy (last_ap, ap); + last_fmt = fmt; + break; + case 'L': #if HAVE_LONG_DOUBLE - (void) va_arg (ap, long double); + (void) va_arg (ap, long double); #else - ASSERT_FAIL (long double not available); + ASSERT_FAIL (long double not available); #endif - break; - default: - (void) va_arg (ap, double); - break; - } - goto next; - - case 'f': - param.conv = DOPRNT_CONV_FIXED; - goto floating; - - case 'F': /* mpf_t */ - case 'j': /* intmax_t */ - case 'L': /* long long */ - case 'N': /* mpn */ - case 'q': /* quad_t */ - case 'Q': /* mpq_t */ - case 't': /* ptrdiff_t */ - case 'z': /* size_t */ - case 'Z': /* mpz_t */ - set_type: - type = fchar; - break; - - case 'G': - param.base = -10; - param.expfmt = "E%c%02d"; - /*FALLTHRU*/ - case 'g': - param.conv = DOPRNT_CONV_GENERAL; - param.showtrailing = 0; - goto floating; - - case 'h': - if (type != 'h') - goto set_type; - type = 'H'; /* internal code for "hh" */ - break; - - case 'l': - if (type != 'l') - goto set_type; - type = 'L'; /* "ll" means "L" */ - break; - - case 'm': - /* glibc strerror(errno), no argument */ - goto next; - - case 'M': /* mp_limb_t */ - /* mung format string to l or ll and let plain printf handle it */ + break; + default: + (void) va_arg (ap, double); + break; + } + goto next; + + case 'f': + param.conv = DOPRNT_CONV_FIXED; + goto floating; + + case 'F': /* mpf_t */ + case 'j': /* intmax_t */ + case 'L': /* long long */ + case 'N': /* mpn */ + case 'q': /* quad_t */ + case 'Q': /* mpq_t */ + case 't': /* ptrdiff_t */ + case 'z': /* size_t */ + case 'Z': /* mpz_t */ + set_type: + type = fchar; + break; + + case 'G': + param.base = -10; + param.expfmt = "E%c%02d"; + /*FALLTHRU*/ + case 'g': + param.conv = DOPRNT_CONV_GENERAL; + param.showtrailing = 0; + goto floating; + + case 'h': + if (type != 'h') + goto set_type; + type = 'H'; /* internal code for "hh" */ + break; + + case 'l': + if (type != 'l') + goto set_type; + type = 'L'; /* "ll" means "L" */ + break; + + case 'm': + /* glibc strerror(errno), no argument */ + goto next; + + case 'M': /* mp_limb_t */ + /* mung format string to l or ll and let plain printf handle it */ #if _LONG_LONG_LIMB - memmove (fmt+1, fmt, strlen (fmt)+1); - fmt[-1] = 'l'; - fmt[0] = 'l'; - fmt++; - type = 'L'; + memmove (fmt+1, fmt, strlen (fmt)+1); + fmt[-1] = 'l'; + fmt[0] = 'l'; + fmt++; + type = 'L'; #else - fmt[-1] = 'l'; - type = 'l'; + fmt[-1] = 'l'; + type = 'l'; #endif - break; - - case 'n': - { - void *p; - FLUSH (); - p = va_arg (ap, void *); - switch (type) { - case '\0': * (int *) p = retval; break; - case 'F': mpf_set_si ((mpf_ptr) p, (long) retval); break; - case 'H': * (char *) p = retval; break; - case 'h': * (short *) p = retval; break; + break; + + case 'n': + { + void *p; + FLUSH (); + p = va_arg (ap, void *); + switch (type) { + case '\0': * (int *) p = retval; break; + case 'F': mpf_set_si ((mpf_ptr) p, (long) retval); break; + case 'H': * (char *) p = retval; break; + case 'h': * (short *) p = retval; break; #if HAVE_INTMAX_T - case 'j': * (intmax_t *) p = retval; break; + case 'j': * (intmax_t *) p = retval; break; #else - case 'j': ASSERT_FAIL (intmax_t not available); break; + case 'j': ASSERT_FAIL (intmax_t not available); break; #endif - case 'l': * (long *) p = retval; break; + case 'l': * (long *) p = retval; break; #if HAVE_QUAD_T && HAVE_LONG_LONG - case 'q': - ASSERT_ALWAYS (sizeof (quad_t) == sizeof (long long)); - /*FALLTHRU*/ + case 'q': + ASSERT_ALWAYS (sizeof (quad_t) == sizeof (long long)); + /*FALLTHRU*/ #else - case 'q': ASSERT_FAIL (quad_t not available); break; + case 'q': ASSERT_FAIL (quad_t not available); break; #endif #if HAVE_LONG_LONG - case 'L': * (long long *) p = retval; break; + case 'L': * (long long *) p = retval; break; #else - case 'L': ASSERT_FAIL (long long not available); break; + case 'L': ASSERT_FAIL (long long not available); break; #endif - case 'N': - { - mp_size_t n; - n = va_arg (ap, mp_size_t); - n = ABS (n); - if (n != 0) - { - * (mp_ptr) p = retval; - MPN_ZERO ((mp_ptr) p + 1, n - 1); - } - } - break; - case 'Q': mpq_set_si ((mpq_ptr) p, (long) retval, 1L); break; + case 'N': + { + mp_size_t n; + n = va_arg (ap, mp_size_t); + n = ABS (n); + if (n != 0) + { + * (mp_ptr) p = retval; + MPN_ZERO ((mp_ptr) p + 1, n - 1); + } + } + break; + case 'Q': mpq_set_si ((mpq_ptr) p, (long) retval, 1L); break; #if HAVE_PTRDIFF_T - case 't': * (ptrdiff_t *) p = retval; break; + case 't': * (ptrdiff_t *) p = retval; break; #else - case 't': ASSERT_FAIL (ptrdiff_t not available); break; + case 't': ASSERT_FAIL (ptrdiff_t not available); break; #endif - case 'z': * (size_t *) p = retval; break; - case 'Z': mpz_set_si ((mpz_ptr) p, (long) retval); break; - } - } - va_copy (last_ap, ap); - last_fmt = fmt; - goto next; - - case 'o': - param.base = 8; - goto integer; - - case 'p': - case 's': - /* "void *" will be good enough for "char *" or "wchar_t *", no - need for separate code. */ - (void) va_arg (ap, const void *); - goto next; - - case 'x': - param.base = 16; - goto integer; - case 'X': - param.base = -16; - goto integer; - - case '%': - goto next; - - case '#': - param.showbase = DOPRNT_SHOWBASE_NONZERO; - break; - - case '\'': - /* glibc digit grouping, just pass it through, no support for it - on gmp types */ - break; - - case '+': - case ' ': - param.sign = fchar; - break; - - case '-': - param.justify = DOPRNT_JUSTIFY_LEFT; - break; - case '.': - seen_precision = 1; - param.prec = -1; /* "." alone means all necessary digits */ - value = ¶m.prec; - break; - - case '*': - { - int n = va_arg (ap, int); - - if (value == ¶m.width) - { - /* negative width means left justify */ - if (n < 0) - { - param.justify = DOPRNT_JUSTIFY_LEFT; - n = -n; - } - param.width = n; - } - else - { - /* don't allow negative precision */ - param.prec = MAX (0, n); - } - } - break; - - case '0': - if (value == ¶m.width) - { - /* in width field, set fill */ - param.fill = '0'; - - /* for right justify, put the fill after any minus sign */ - if (param.justify == DOPRNT_JUSTIFY_RIGHT) - param.justify = DOPRNT_JUSTIFY_INTERNAL; - } - else - { - /* in precision field, set value */ - *value = 0; - } - break; - - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - /* process all digits to form a value */ - { - int n = 0; - do { - n = n * 10 + (fchar-'0'); - fchar = *fmt++; - } while (isascii (fchar) && isdigit (fchar)); - fmt--; /* unget the non-digit */ - *value = n; - } - break; - - default: - /* something invalid */ - ASSERT (0); - goto next; - } - } + case 'z': * (size_t *) p = retval; break; + case 'Z': mpz_set_si ((mpz_ptr) p, (long) retval); break; + } + } + va_copy (last_ap, ap); + last_fmt = fmt; + goto next; + + case 'o': + param.base = 8; + goto integer; + + case 'p': + case 's': + /* "void *" will be good enough for "char *" or "wchar_t *", no + need for separate code. */ + (void) va_arg (ap, const void *); + goto next; + + case 'x': + param.base = 16; + goto integer; + case 'X': + param.base = -16; + goto integer; + + case '%': + goto next; + + case '#': + param.showbase = DOPRNT_SHOWBASE_NONZERO; + break; + + case '\'': + /* glibc digit grouping, just pass it through, no support for it + on gmp types */ + break; + + case '+': + case ' ': + param.sign = fchar; + break; + + case '-': + param.justify = DOPRNT_JUSTIFY_LEFT; + break; + case '.': + seen_precision = 1; + param.prec = -1; /* "." alone means all necessary digits */ + value = ¶m.prec; + break; + + case '*': + { + int n = va_arg (ap, int); + + if (value == ¶m.width) + { + /* negative width means left justify */ + if (n < 0) + { + param.justify = DOPRNT_JUSTIFY_LEFT; + n = -n; + } + param.width = n; + } + else + { + /* don't allow negative precision */ + param.prec = MAX (0, n); + } + } + break; + + case '0': + if (value == ¶m.width) + { + /* in width field, set fill */ + param.fill = '0'; + + /* for right justify, put the fill after any minus sign */ + if (param.justify == DOPRNT_JUSTIFY_RIGHT) + param.justify = DOPRNT_JUSTIFY_INTERNAL; + } + else + { + /* in precision field, set value */ + *value = 0; + } + break; + + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + /* process all digits to form a value */ + { + int n = 0; + do { + n = n * 10 + (fchar-'0'); + fchar = *fmt++; + } while (isascii (fchar) && isdigit (fchar)); + fmt--; /* unget the non-digit */ + *value = n; + } + break; + + default: + /* something invalid */ + ASSERT (0); + goto next; + } + } next: /* Stop parsing the current "%" format, look for a new one. */ diff --git a/printf/doprntf.c b/printf/doprntf.c index 9c0608b1e..e713a21a0 100644 --- a/printf/doprntf.c +++ b/printf/doprntf.c @@ -39,7 +39,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ /* change this to "#define TRACE(x) x" for diagnostics */ -#define TRACE(x) +#define TRACE(x) /* The separate of __gmp_doprnt_float_digits and __gmp_doprnt_float is so @@ -52,10 +52,10 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, - void *data, - const struct doprnt_params_t *p, - const char *point, - mpf_srcptr f) + void *data, + const struct doprnt_params_t *p, + const char *point, + mpf_srcptr f) { int prec, ndigits, free_size, len, newlen, justify, justlen, explen; int showbaselen, sign, signlen, intlen, intzeros, pointlen; @@ -67,7 +67,7 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, int retval = 0; TRACE (printf ("__gmp_doprnt_float\n"); - printf (" conv=%d prec=%d\n", p->conv, p->prec)); + printf (" conv=%d prec=%d\n", p->conv, p->prec)); prec = p->prec; if (prec <= -1) @@ -76,40 +76,40 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, ndigits = 0; /* arrange the fixed/scientific decision on a "prec" implied by how - many significant digits there are */ + many significant digits there are */ if (p->conv == DOPRNT_CONV_GENERAL) - MPF_SIGNIFICANT_DIGITS (prec, PREC(f), ABS(p->base)); + MPF_SIGNIFICANT_DIGITS (prec, PREC(f), ABS(p->base)); } else { switch (p->conv) { case DOPRNT_CONV_FIXED: - /* Precision is digits after the radix point. Try not to generate - too many more than will actually be required. If f>=1 then - overestimate the integer part, and add prec. If f<1 then - underestimate the zeros between the radix point and the first - digit and subtract that from prec. In either case add 2 so the - round to nearest can be applied accurately. */ - ndigits = prec + 2 - + EXP(f) * (__mp_bases[ABS(p->base)].chars_per_limb + (EXP(f)>=0)); - ndigits = MAX (ndigits, 1); - break; + /* Precision is digits after the radix point. Try not to generate + too many more than will actually be required. If f>=1 then + overestimate the integer part, and add prec. If f<1 then + underestimate the zeros between the radix point and the first + digit and subtract that from prec. In either case add 2 so the + round to nearest can be applied accurately. */ + ndigits = prec + 2 + + EXP(f) * (__mp_bases[ABS(p->base)].chars_per_limb + (EXP(f)>=0)); + ndigits = MAX (ndigits, 1); + break; case DOPRNT_CONV_SCIENTIFIC: - /* precision is digits after the radix point, and there's one digit - before */ - ndigits = prec + 1; - break; + /* precision is digits after the radix point, and there's one digit + before */ + ndigits = prec + 1; + break; default: - ASSERT (0); - /*FALLTHRU*/ - + ASSERT (0); + /*FALLTHRU*/ + case DOPRNT_CONV_GENERAL: - /* precision is total digits, but be sure to ask mpf_get_str for at - least 1, not 0 */ - ndigits = MAX (prec, 1); - break; + /* precision is total digits, but be sure to ask mpf_get_str for at + least 1, not 0 */ + ndigits = MAX (prec, 1); + break; } } TRACE (printf (" ndigits %d\n", ndigits)); @@ -119,13 +119,13 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, free_ptr = s; free_size = len + 1; TRACE (printf (" s %s\n", s); - printf (" exp %ld\n", exp); - printf (" len %d\n", len)); + printf (" exp %ld\n", exp); + printf (" len %d\n", len)); /* For fixed mode check the ndigits formed above was in fact enough for the integer part plus p->prec after the radix point. */ ASSERT ((p->conv == DOPRNT_CONV_FIXED && p->prec > -1) - ? ndigits >= MAX (1, exp + p->prec + 2) : 1); + ? ndigits >= MAX (1, exp + p->prec + 2) : 1); sign = p->sign; if (s[0] == '-') @@ -146,85 +146,85 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, newlen = exp + prec; if (newlen < 0) { - /* first non-zero digit is below target prec, and at least one zero - digit in between, so print zero */ - len = 0; - exp = 0; + /* first non-zero digit is below target prec, and at least one zero + digit in between, so print zero */ + len = 0; + exp = 0; } else if (len <= newlen) { - /* already got few enough digits */ + /* already got few enough digits */ } else { - /* discard excess digits and round to nearest */ - - const char *num_to_text = (p->base >= 0 - ? "0123456789abcdefghijklmnopqrstuvwxyz" - : "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - int base = ABS(p->base); - int n; - - ASSERT (base <= 36); - - len = newlen; - n = DIGIT_VALUE (s[len]); - TRACE (printf (" rounding with %d\n", n)); - if (n >= (base + 1) / 2) - { - /* propagate a carry */ - for (;;) - { - if (len == 0) - { - s[0] = '1'; - len = 1; - exp++; - break; - } - n = DIGIT_VALUE (s[len-1]); - ASSERT (n >= 0 && n < base); - n++; - if (n != base) - { - TRACE (printf (" storing now %d\n", n)); - s[len-1] = num_to_text[n]; - break; - } - len--; - } - } - else - { - /* truncate only, strip any trailing zeros now exposed */ - while (len > 0 && s[len-1] == '0') - len--; - } - - /* Can have newlen==0, in which case the truncate was just to check - for a carry turning it into "1". If we're left with len==0 then - adjust exp to match. */ - if (len == 0) - exp = 0; - } + /* discard excess digits and round to nearest */ + + const char *num_to_text = (p->base >= 0 + ? "0123456789abcdefghijklmnopqrstuvwxyz" + : "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + int base = ABS(p->base); + int n; + + ASSERT (base <= 36); + + len = newlen; + n = DIGIT_VALUE (s[len]); + TRACE (printf (" rounding with %d\n", n)); + if (n >= (base + 1) / 2) + { + /* propagate a carry */ + for (;;) + { + if (len == 0) + { + s[0] = '1'; + len = 1; + exp++; + break; + } + n = DIGIT_VALUE (s[len-1]); + ASSERT (n >= 0 && n < base); + n++; + if (n != base) + { + TRACE (printf (" storing now %d\n", n)); + s[len-1] = num_to_text[n]; + break; + } + len--; + } + } + else + { + /* truncate only, strip any trailing zeros now exposed */ + while (len > 0 && s[len-1] == '0') + len--; + } + + /* Can have newlen==0, in which case the truncate was just to check + for a carry turning it into "1". If we're left with len==0 then + adjust exp to match. */ + if (len == 0) + exp = 0; + } fixed: ASSERT (len == 0 ? exp == 0 : 1); if (exp <= 0) { - TRACE (printf (" fixed 0.000sss\n")); - intlen = 0; - intzeros = 1; - fraczeros = -exp; - fraclen = len; + TRACE (printf (" fixed 0.000sss\n")); + intlen = 0; + intzeros = 1; + fraczeros = -exp; + fraclen = len; } else { - TRACE (printf (" fixed sss.sss or sss000\n")); - intlen = MIN (len, exp); - intzeros = exp - intlen; - fraczeros = 0; - fraclen = len - intlen; + TRACE (printf (" fixed sss.sss or sss000\n")); + intlen = MIN (len, exp); + intzeros = exp - intlen; + fraczeros = 0; + fraclen = len - intlen; } explen = 0; break; @@ -235,7 +235,7 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, char expsign; if (prec <= -1) - prec = MAX (0, len-1); /* retain all digits */ + prec = MAX (0, len-1); /* retain all digits */ scientific: TRACE (printf (" scientific s.sss\n")); @@ -247,18 +247,18 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, expval = (exp-intlen); if (p->exptimes4) - expval <<= 2; + expval <<= 2; /* Split out the sign since %o or %x in expfmt give negatives as twos - complement, not with a sign. */ + complement, not with a sign. */ expsign = (expval >= 0 ? '+' : '-'); expval = ABS (expval); #if HAVE_VSNPRINTF explen = snprintf (exponent, sizeof(exponent), - p->expfmt, expsign, expval); + p->expfmt, expsign, expval); /* test for < sizeof-1 since a glibc 2.0.x return of sizeof-1 might - mean truncation */ + mean truncation */ ASSERT (explen >= 0 && explen < sizeof(exponent)-1); #else sprintf (exponent, p->expfmt, expsign, expval); @@ -286,24 +286,24 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, } TRACE (printf (" intlen %d intzeros %d fraczeros %d fraclen %d\n", - intlen, intzeros, fraczeros, fraclen)); + intlen, intzeros, fraczeros, fraclen)); ASSERT (p->prec <= -1 - ? intlen + fraclen == strlen (s) - : intlen + fraclen <= strlen (s)); + ? intlen + fraclen == strlen (s) + : intlen + fraclen <= strlen (s)); if (p->showtrailing) { /* Pad to requested precision with trailing zeros, for general this is - all digits, for fixed and scientific just the fraction. */ + all digits, for fixed and scientific just the fraction. */ preczeros = prec - (fraczeros + fraclen - + (p->conv == DOPRNT_CONV_GENERAL - ? intlen + intzeros : 0)); + + (p->conv == DOPRNT_CONV_GENERAL + ? intlen + intzeros : 0)); preczeros = MAX (0, preczeros); } else preczeros = 0; TRACE (printf (" prec=%d showtrailing=%d, pad with preczeros %d\n", - prec, p->showtrailing, preczeros)); + prec, p->showtrailing, preczeros)); /* radix point if needed, or if forced */ pointlen = ((fraczeros + fraclen + preczeros) != 0 || p->showpoint != 0) @@ -333,11 +333,11 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, break; } TRACE (printf (" showbase %s showbaselen %d\n", - showbase == NULL ? "" : showbase, showbaselen)); + showbase == NULL ? "" : showbase, showbaselen)); /* left over field width */ justlen = p->width - (signlen + showbaselen + intlen + intzeros + pointlen - + fraczeros + fraclen + preczeros + explen); + + fraczeros + fraclen + preczeros + explen); TRACE (printf (" justlen %d fill 0x%X\n", justlen, p->fill)); justify = p->justify; @@ -345,7 +345,7 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, justify = DOPRNT_JUSTIFY_NONE; TRACE (printf (" justify type %d intlen %d pointlen %d fraclen %d\n", - justify, intlen, pointlen, fraclen)); + justify, intlen, pointlen, fraclen)); if (justify == DOPRNT_JUSTIFY_RIGHT) /* pad for right */ DOPRNT_REPS (p->fill, justlen); @@ -370,7 +370,7 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, DOPRNT_MEMORY_MAYBE (exponent, explen); /* exp */ - if (justify == DOPRNT_JUSTIFY_LEFT) /* pad for left */ + if (justify == DOPRNT_JUSTIFY_LEFT) /* pad for left */ DOPRNT_REPS (p->fill, justlen); done: diff --git a/printf/doprnti.c b/printf/doprnti.c index 1202eaacc..df474df3e 100644 --- a/printf/doprnti.c +++ b/printf/doprnti.c @@ -39,9 +39,9 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int __gmp_doprnt_integer (const struct doprnt_funs_t *funs, - void *data, - const struct doprnt_params_t *p, - const char *s) + void *data, + const struct doprnt_params_t *p, + const char *s) { int retval = 0; int slen, justlen, showbaselen, sign, signlen, slashlen, zeros; diff --git a/printf/obprntffuns.c b/printf/obprntffuns.c index 256c6b3bb..092e6cca2 100644 --- a/printf/obprntffuns.c +++ b/printf/obprntffuns.c @@ -46,7 +46,7 @@ static int gmp_obstack_memory (struct obstack *ob, const char *ptr, size_t len) { obstack_grow (ob, ptr, len); - return len; + return len; } static int diff --git a/printf/repl-vsnprintf.c b/printf/repl-vsnprintf.c index 5587c5b7b..06809dcb8 100644 --- a/printf/repl-vsnprintf.c +++ b/printf/repl-vsnprintf.c @@ -92,7 +92,7 @@ strnlen (const char *s, size_t n) int __gmp_replacement_vsnprintf (char *buf, size_t buf_size, - const char *orig_fmt, va_list orig_ap) + const char *orig_fmt, va_list orig_ap) { va_list ap; const char *fmt; @@ -127,7 +127,7 @@ __gmp_replacement_vsnprintf (char *buf, size_t buf_size, #ifdef DBL_MAX_10_EXP /* but in any case prefer a value the compiler says */ double_digits = DBL_MAX_10_EXP; -#endif +#endif /* IEEE 128-bit quad, Intel 80-bit temporary, or VAX H floats all have 15 bit exponents, so the default is a maximum 4932 decimal digits. */ @@ -140,13 +140,13 @@ __gmp_replacement_vsnprintf (char *buf, size_t buf_size, #ifdef LDBL_MAX_10_EXP /* but in any case prefer a value the compiler says */ long_double_digits = LDBL_MAX_10_EXP; -#endif +#endif for (;;) { fmt = strchr (fmt, '%'); if (fmt == NULL) - break; + break; fmt++; type = '\0'; @@ -156,202 +156,202 @@ __gmp_replacement_vsnprintf (char *buf, size_t buf_size, value = &width; for (;;) - { - fchar = *fmt++; - switch (fchar) { - - case 'c': - /* char, already accounted for by strlen(fmt) */ - goto next; - - case 'd': - case 'i': - case 'o': - case 'x': - case 'X': - case 'u': - /* at most 3 digits per byte in hex, dec or octal, plus a sign */ - total_width += 3 * integer_sizeof + 1; - - switch (type) { - case 'j': - /* Let's assume uintmax_t is the same size as intmax_t. */ + { + fchar = *fmt++; + switch (fchar) { + + case 'c': + /* char, already accounted for by strlen(fmt) */ + goto next; + + case 'd': + case 'i': + case 'o': + case 'x': + case 'X': + case 'u': + /* at most 3 digits per byte in hex, dec or octal, plus a sign */ + total_width += 3 * integer_sizeof + 1; + + switch (type) { + case 'j': + /* Let's assume uintmax_t is the same size as intmax_t. */ #if HAVE_INTMAX_T - (void) va_arg (ap, intmax_t); + (void) va_arg (ap, intmax_t); #else - ASSERT_FAIL (intmax_t not available); + ASSERT_FAIL (intmax_t not available); #endif - break; - case 'l': - (void) va_arg (ap, long); - break; - case 'L': + break; + case 'l': + (void) va_arg (ap, long); + break; + case 'L': #if HAVE_LONG_LONG - (void) va_arg (ap, long long); + (void) va_arg (ap, long long); #else - ASSERT_FAIL (long long not available); + ASSERT_FAIL (long long not available); #endif - break; - case 'q': - /* quad_t is probably the same as long long, but let's treat - it separately just to be sure. Also let's assume u_quad_t - will be the same size as quad_t. */ + break; + case 'q': + /* quad_t is probably the same as long long, but let's treat + it separately just to be sure. Also let's assume u_quad_t + will be the same size as quad_t. */ #if HAVE_QUAD_T - (void) va_arg (ap, quad_t); + (void) va_arg (ap, quad_t); #else - ASSERT_FAIL (quad_t not available); + ASSERT_FAIL (quad_t not available); #endif - break; - case 't': + break; + case 't': #if HAVE_PTRDIFF_T - (void) va_arg (ap, ptrdiff_t); + (void) va_arg (ap, ptrdiff_t); #else - ASSERT_FAIL (ptrdiff_t not available); + ASSERT_FAIL (ptrdiff_t not available); #endif - break; - case 'z': - (void) va_arg (ap, size_t); - break; - default: - /* default is an "int", and this includes h=short and hh=char - since they're promoted to int in a function call */ - (void) va_arg (ap, int); - break; - } - goto next; - - case 'E': - case 'e': - case 'G': - case 'g': - /* Requested decimals, sign, point and e, plus an overestimate - of exponent digits (the assumption is all the float is - exponent!). */ - total_width += prec + 3 + floating_sizeof * 3; - if (type == 'L') - { + break; + case 'z': + (void) va_arg (ap, size_t); + break; + default: + /* default is an "int", and this includes h=short and hh=char + since they're promoted to int in a function call */ + (void) va_arg (ap, int); + break; + } + goto next; + + case 'E': + case 'e': + case 'G': + case 'g': + /* Requested decimals, sign, point and e, plus an overestimate + of exponent digits (the assumption is all the float is + exponent!). */ + total_width += prec + 3 + floating_sizeof * 3; + if (type == 'L') + { #if HAVE_LONG_DOUBLE - (void) va_arg (ap, long double); + (void) va_arg (ap, long double); #else - ASSERT_FAIL (long double not available); + ASSERT_FAIL (long double not available); #endif - } - else + } + else (void) va_arg (ap, double); - break; - - case 'f': - /* Requested decimals, sign and point, and a margin for error, - then add the maximum digits that can be in the integer part, - based on the maximum exponent value. */ - total_width += prec + 2 + 10; - if (type == 'L') - { + break; + + case 'f': + /* Requested decimals, sign and point, and a margin for error, + then add the maximum digits that can be in the integer part, + based on the maximum exponent value. */ + total_width += prec + 2 + 10; + if (type == 'L') + { #if HAVE_LONG_DOUBLE - (void) va_arg (ap, long double); - total_width += long_double_digits; + (void) va_arg (ap, long double); + total_width += long_double_digits; #else - ASSERT_FAIL (long double not available); + ASSERT_FAIL (long double not available); #endif - } - else - { - (void) va_arg (ap, double); - total_width += double_digits; - } - break; - - case 'h': /* short or char */ - case 'j': /* intmax_t */ - case 'L': /* long long or long double */ - case 'q': /* quad_t */ - case 't': /* ptrdiff_t */ - set_type: - type = fchar; - break; - - case 'l': - /* long or long long */ - if (type != 'l') - goto set_type; - type = 'L'; /* "ll" means "L" */ - break; - - case 'n': - /* bytes written, no output as such */ - (void) va_arg (ap, void *); - goto next; - - case 's': - /* If no precision was given, then determine the string length - and put it there, to be added to the total under "next". If - a precision was given then that's already the maximum from - this field, but see whether the string is shorter than that, - in case the limit was very big. */ - { - const char *s = va_arg (ap, const char *); - prec = (seen_prec ? strnlen (s, prec) : strlen (s)); - } - goto next; - - case 'p': - /* pointer, let's assume at worst it's octal with some padding */ - (void) va_arg (ap, const void *); - total_width += 3 * sizeof (void *) + 16; - goto next; - - case '%': - /* literal %, already accounted for by strlen(fmt) */ - goto next; - - case '#': - /* showbase, at most 2 for "0x" */ - total_width += 2; - break; - - case '+': - case ' ': - /* sign, already accounted for under numerics */ - break; - - case '-': - /* left justify, no effect on total width */ - break; - - case '.': - seen_prec = 1; - value = ≺ - break; - - case '*': - { - /* negative width means left justify which can be ignored, - negative prec would be invalid, just use absolute value */ - int n = va_arg (ap, int); - *value = ABS (n); - } - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* process all digits to form a value */ - { - int n = 0; - do { - n = n * 10 + (fchar-'0'); - fchar = *fmt++; - } while (isascii (fchar) && isdigit (fchar)); - fmt--; /* unget the non-digit */ - *value = n; - } - break; - - default: - /* incomplete or invalid % sequence */ - ASSERT (0); - goto next; - } - } + } + else + { + (void) va_arg (ap, double); + total_width += double_digits; + } + break; + + case 'h': /* short or char */ + case 'j': /* intmax_t */ + case 'L': /* long long or long double */ + case 'q': /* quad_t */ + case 't': /* ptrdiff_t */ + set_type: + type = fchar; + break; + + case 'l': + /* long or long long */ + if (type != 'l') + goto set_type; + type = 'L'; /* "ll" means "L" */ + break; + + case 'n': + /* bytes written, no output as such */ + (void) va_arg (ap, void *); + goto next; + + case 's': + /* If no precision was given, then determine the string length + and put it there, to be added to the total under "next". If + a precision was given then that's already the maximum from + this field, but see whether the string is shorter than that, + in case the limit was very big. */ + { + const char *s = va_arg (ap, const char *); + prec = (seen_prec ? strnlen (s, prec) : strlen (s)); + } + goto next; + + case 'p': + /* pointer, let's assume at worst it's octal with some padding */ + (void) va_arg (ap, const void *); + total_width += 3 * sizeof (void *) + 16; + goto next; + + case '%': + /* literal %, already accounted for by strlen(fmt) */ + goto next; + + case '#': + /* showbase, at most 2 for "0x" */ + total_width += 2; + break; + + case '+': + case ' ': + /* sign, already accounted for under numerics */ + break; + + case '-': + /* left justify, no effect on total width */ + break; + + case '.': + seen_prec = 1; + value = ≺ + break; + + case '*': + { + /* negative width means left justify which can be ignored, + negative prec would be invalid, just use absolute value */ + int n = va_arg (ap, int); + *value = ABS (n); + } + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* process all digits to form a value */ + { + int n = 0; + do { + n = n * 10 + (fchar-'0'); + fchar = *fmt++; + } while (isascii (fchar) && isdigit (fchar)); + fmt--; /* unget the non-digit */ + *value = n; + } + break; + + default: + /* incomplete or invalid % sequence */ + ASSERT (0); + goto next; + } + } next: total_width += width; @@ -371,11 +371,11 @@ __gmp_replacement_vsnprintf (char *buf, size_t buf_size, vsprintf (s, orig_fmt, orig_ap); len = strlen (s); if (buf_size != 0) - { - size_t copylen = MIN (len, buf_size-1); - memcpy (buf, s, copylen); - buf[copylen] = '\0'; - } + { + size_t copylen = MIN (len, buf_size-1); + memcpy (buf, s, copylen); + buf[copylen] = '\0'; + } (*__gmp_free_func) (s, total_width); } diff --git a/printf/sprintffuns.c b/printf/sprintffuns.c index 7a4dc6264..01fb3c98e 100644 --- a/printf/sprintffuns.c +++ b/printf/sprintffuns.c @@ -53,7 +53,7 @@ gmp_sprintf_format (char **bufp, const char *fmt, va_list ap) vsprintf (buf, fmt, ap); ret = strlen (buf); *bufp = buf + ret; - return ret; + return ret; } static int @@ -62,7 +62,7 @@ gmp_sprintf_memory (char **bufp, const char *str, size_t len) char *buf = *bufp; *bufp = buf + len; memcpy (buf, str, len); - return len; + return len; } static int @@ -72,7 +72,7 @@ gmp_sprintf_reps (char **bufp, int c, int reps) ASSERT (reps >= 0); *bufp = buf + reps; memset (buf, c, reps); - return reps; + return reps; } static int diff --git a/tests/cxx/t-ostream.cc b/tests/cxx/t-ostream.cc index e27c3642b..0eeb7be62 100644 --- a/tests/cxx/t-ostream.cc +++ b/tests/cxx/t-ostream.cc @@ -30,27 +30,27 @@ using namespace std; int option_check_standard = 0; -#define CALL(expr) \ - do { \ - got.flags (data[i].flags); \ - got.width (data[i].width); \ - got.precision (data[i].precision); \ - if (data[i].fill == '\0') \ - got.fill (' '); \ - else \ - got.fill (data[i].fill); \ - \ - if (! (expr)) \ - { \ - cout << "\"got\" output error\n"; \ - abort (); \ - } \ - if (got.width() != 0) \ - { \ - cout << "\"got\" width not reset to 0\n"; \ - abort (); \ - } \ - \ +#define CALL(expr) \ + do { \ + got.flags (data[i].flags); \ + got.width (data[i].width); \ + got.precision (data[i].precision); \ + if (data[i].fill == '\0') \ + got.fill (' '); \ + else \ + got.fill (data[i].fill); \ + \ + if (! (expr)) \ + { \ + cout << "\"got\" output error\n"; \ + abort (); \ + } \ + if (got.width() != 0) \ + { \ + cout << "\"got\" width not reset to 0\n"; \ + abort (); \ + } \ + \ } while (0) @@ -144,15 +144,15 @@ check_mpz (void) : 1) ) { - ostringstream got; - long n = mpz_get_si (z); + ostringstream got; + long n = mpz_get_si (z); CALL (got << n); if (got.str().compare (data[i].want) != 0) { cout << "check_mpz data[" << i << "] doesn't match standard ostream output\n"; - cout << " z: " << data[i].z << "\n"; - cout << " n: " << n << "\n"; + cout << " z: " << data[i].z << "\n"; + cout << " n: " << n << "\n"; DUMP (); } } @@ -176,12 +176,12 @@ void check_mpq (void) { static const struct { - const char *q; - const char *want; + const char *q; + const char *want; ios::fmtflags flags; - int width; - int precision; - char fill; + int width; + int precision; + char fill; } data[] = { @@ -208,7 +208,7 @@ check_mpq (void) }; size_t i; - mpq_t q; + mpq_t q; mpq_init (q); @@ -224,15 +224,15 @@ check_mpq (void) && mpz_fits_slong_p (mpq_numref(q)) && mpq_integer_p (q)) { - ostringstream got; - long n = mpz_get_si (mpq_numref(q)); + ostringstream got; + long n = mpz_get_si (mpq_numref(q)); CALL (got << n); if (got.str().compare (data[i].want) != 0) { cout << "check_mpq data[" << i << "] doesn't match standard ostream output\n"; - cout << " q: " << data[i].q << "\n"; - cout << " n: " << n << "\n"; + cout << " q: " << data[i].q << "\n"; + cout << " n: " << n << "\n"; DUMP (); } } @@ -257,56 +257,56 @@ void check_mpf (void) { static const struct { - const char *f; - const char *want; + const char *f; + const char *want; ios::fmtflags flags; - int width; - int precision; - char fill; + int width; + int precision; + char fill; } data[] = { - { "0", "0", ios::dec }, - { "0", "+0", ios::dec | ios::showpos }, - { "0", "0.00000", ios::dec | ios::showpoint }, - { "0", "0", ios::dec | ios::fixed }, - { "0", "0.", ios::dec | ios::fixed | ios::showpoint }, + { "0", "0", ios::dec }, + { "0", "+0", ios::dec | ios::showpos }, + { "0", "0.00000", ios::dec | ios::showpoint }, + { "0", "0", ios::dec | ios::fixed }, + { "0", "0.", ios::dec | ios::fixed | ios::showpoint }, { "0", "0.000000e+00", ios::dec | ios::scientific }, { "0", "0.000000e+00", ios::dec | ios::scientific | ios::showpoint }, - - { "0", "0", ios::dec, 0, 4 }, - { "0", "0.000", ios::dec | ios::showpoint, 0, 4 }, - { "0", "0.0000", ios::dec | ios::fixed, 0, 4 }, - { "0", "0.0000", ios::dec | ios::fixed | ios::showpoint, 0, 4 }, + + { "0", "0", ios::dec, 0, 4 }, + { "0", "0.000", ios::dec | ios::showpoint, 0, 4 }, + { "0", "0.0000", ios::dec | ios::fixed, 0, 4 }, + { "0", "0.0000", ios::dec | ios::fixed | ios::showpoint, 0, 4 }, { "0", "0.0000e+00", ios::dec | ios::scientific, 0, 4 }, { "0", "0.0000e+00", ios::dec | ios::scientific | ios::showpoint, 0, 4 }, - - { "1", "1", ios::dec }, + + { "1", "1", ios::dec }, { "1", "+1", ios::dec | ios::showpos }, { "1", "1.00000", ios::dec | ios::showpoint }, - { "1", "1", ios::dec | ios::fixed }, + { "1", "1", ios::dec | ios::fixed }, { "1", "1.", ios::dec | ios::fixed | ios::showpoint }, { "1", "1.000000e+00", ios::dec | ios::scientific }, { "1", "1.000000e+00", ios::dec | ios::scientific | ios::showpoint }, - - { "1", "1", ios::dec, 0, 4 }, - { "1", "1.000", ios::dec | ios::showpoint, 0, 4 }, - { "1", "1.0000", ios::dec | ios::fixed, 0, 4 }, - { "1", "1.0000", ios::dec | ios::fixed | ios::showpoint, 0, 4 }, + + { "1", "1", ios::dec, 0, 4 }, + { "1", "1.000", ios::dec | ios::showpoint, 0, 4 }, + { "1", "1.0000", ios::dec | ios::fixed, 0, 4 }, + { "1", "1.0000", ios::dec | ios::fixed | ios::showpoint, 0, 4 }, { "1", "1.0000e+00", ios::dec | ios::scientific, 0, 4 }, { "1", "1.0000e+00", ios::dec | ios::scientific | ios::showpoint, 0, 4 }, - { "-1", "-1", ios::dec | ios::showpos }, + { "-1", "-1", ios::dec | ios::showpos }, - { "-1", " -1", ios::dec, 4 }, - { "-1", "- 1", ios::dec | ios::internal, 4 }, - { "-1", "-1 ", ios::dec | ios::left, 4 }, + { "-1", " -1", ios::dec, 4 }, + { "-1", "- 1", ios::dec | ios::internal, 4 }, + { "-1", "-1 ", ios::dec | ios::left, 4 }, - { "-1", " -0x1", ios::hex | ios::showbase, 6 }, - { "-1", "-0x 1", ios::hex | ios::showbase | ios::internal, 6 }, - { "-1", "-0x1 ", ios::hex | ios::showbase | ios::left, 6 }, + { "-1", " -0x1", ios::hex | ios::showbase, 6 }, + { "-1", "-0x 1", ios::hex | ios::showbase | ios::internal, 6 }, + { "-1", "-0x1 ", ios::hex | ios::showbase | ios::left, 6 }, - { "1", "*********1", ios::dec, 10, 4, '*' }, + { "1", "*********1", ios::dec, 10, 4, '*' }, { "1234", "******1234", ios::dec, 10, 4, '*' }, { "1234", "*****1234.", ios::dec | ios::showpoint, 10, 4, '*' }, @@ -316,12 +316,12 @@ check_mpf (void) { "1.9999999", "2", ios::dec, 0, 1 }, { "1.0009999999", "1.001", ios::dec, 0, 4 }, - { "1.0001", "1", ios::dec, 0, 4 }, - { "1.0004", "1", ios::dec, 0, 4 }, + { "1.0001", "1", ios::dec, 0, 4 }, + { "1.0004", "1", ios::dec, 0, 4 }, { "1.000555", "1.001", ios::dec, 0, 4 }, - { "1.0002", "1.000", ios::dec | ios::fixed, 0, 3 }, - { "1.0008", "1.001", ios::dec | ios::fixed, 0, 3 }, + { "1.0002", "1.000", ios::dec | ios::fixed, 0, 3 }, + { "1.0008", "1.001", ios::dec | ios::fixed, 0, 3 }, { "0", "0", ios::hex }, { "0", "0x0", ios::hex | ios::showbase }, @@ -351,13 +351,13 @@ check_mpf (void) // octal showbase suppressed for 0 { "0", "0", ios::oct | ios::showbase }, - { ".125", "00.1", ios::oct | ios::showbase, 0, 1 }, + { ".125", "00.1", ios::oct | ios::showbase, 0, 1 }, { ".015625", "00.01", ios::oct | ios::showbase, 0, 2 }, - { ".125", "00.1", ios::fixed | ios::oct | ios::showbase, 0, 1 }, - { ".015625", "0.0", ios::fixed | ios::oct | ios::showbase, 0, 1 }, + { ".125", "00.1", ios::fixed | ios::oct | ios::showbase, 0, 1 }, + { ".015625", "0.0", ios::fixed | ios::oct | ios::showbase, 0, 1 }, { ".015625", "00.01", ios::fixed | ios::oct | ios::showbase, 0, 2 }, - { "0.125", "1.000000e-01", ios::oct | ios::scientific }, + { "0.125", "1.000000e-01", ios::oct | ios::scientific }, { "0.125", "+1.000000e-01", ios::oct | ios::scientific | ios::showpos }, { "-0.125", "-1.000000e-01", ios::oct | ios::scientific }, { "-0.125", "-1.000000e-01", ios::oct | ios::scientific | ios::showpos }, @@ -388,7 +388,7 @@ check_mpf (void) }; size_t i; - mpf_t f, f2; + mpf_t f, f2; double d; mpf_init (f); @@ -403,14 +403,14 @@ check_mpf (void) if (option_check_standard && mpf_cmp (f, f2) == 0 && ! (data[i].flags & (ios::hex | ios::oct | ios::showbase))) { - ostringstream got; + ostringstream got; CALL (got << d); if (got.str().compare (data[i].want) != 0) { cout << "check_mpf data[" << i << "] doesn't match standard ostream output\n"; - cout << " f: " << data[i].f << "\n"; - cout << " d: " << d << "\n"; + cout << " f: " << data[i].f << "\n"; + cout << " d: " << d << "\n"; DUMP (); } } diff --git a/tests/misc.c b/tests/misc.c index 2b2f9db42..4aa9bdf1d 100644 --- a/tests/misc.c +++ b/tests/misc.c @@ -563,4 +563,3 @@ tests_sigfpe_done (void) { signal (SIGFPE, SIG_DFL); } - diff --git a/tests/misc/t-printf.c b/tests/misc/t-printf.c index e7134ce1e..dc35f33af 100644 --- a/tests/misc/t-printf.c +++ b/tests/misc/t-printf.c @@ -107,22 +107,22 @@ check_plain (va_alist) switch (*p) { case 'a': case 'A': - /* The exact value of the exponent isn't guaranteed in glibc, and it - and gmp_printf do slightly different things, so don't compare - directly. */ - goto done; + /* The exact value of the exponent isn't guaranteed in glibc, and it + and gmp_printf do slightly different things, so don't compare + directly. */ + goto done; case 'F': - if (p > fmt_orig && *(p-1) == '.') - goto done; /* don't test the "all digits" cases */ - /* discard 'F' type */ - break; + if (p > fmt_orig && *(p-1) == '.') + goto done; /* don't test the "all digits" cases */ + /* discard 'F' type */ + break; case 'Z': - /* transmute */ - *q++ = 'l'; - break; + /* transmute */ + *q++ = 'l'; + break; default: - *q++ = *p; - break; + *q++ = *p; + break; } } *q = '\0'; @@ -152,7 +152,7 @@ check_vsprintf (const char *want, const char *fmt, va_list ap) { char got[MAX_OUTPUT]; int got_len, want_len; - + want_len = strlen (want); got_len = gmp_vsprintf (got, fmt, ap); @@ -212,7 +212,7 @@ check_vsnprintf (const char *want, const char *fmt, va_list ap) char got[MAX_OUTPUT+1]; int ret, got_len, want_len; size_t bufsize; - + want_len = strlen (want); bufsize = -1; @@ -221,9 +221,9 @@ check_vsnprintf (const char *want, const char *fmt, va_list ap) /* do 0 to 5, then want-5 to want+5 */ bufsize++; if (bufsize > 5 && bufsize < want_len-5) - bufsize = want_len-5; + bufsize = want_len-5; if (bufsize > want_len + 5) - break; + break; ASSERT_ALWAYS (bufsize+1 <= sizeof (got)); got[bufsize] = '!'; @@ -232,33 +232,33 @@ check_vsnprintf (const char *want, const char *fmt, va_list ap) got_len = MIN (MAX(1,bufsize)-1, want_len); if (got[bufsize] != '!') - { - printf ("gmp_vsnprintf overwrote bufsize sentinel\n"); - goto error; - } + { + printf ("gmp_vsnprintf overwrote bufsize sentinel\n"); + goto error; + } if (ret != want_len) - { - printf ("gmp_vsnprintf return value wrong\n"); - goto error; - } + { + printf ("gmp_vsnprintf return value wrong\n"); + goto error; + } if (bufsize > 0) - { - if (memcmp (got, want, got_len) != 0 || got[got_len] != '\0') - { - printf ("gmp_vsnprintf wrong result string\n"); - error: - printf (" fmt |%s|\n", fmt); - printf (" bufsize %u\n", bufsize); - printf (" got |%s|\n", got); - printf (" want |%.*s|\n", got_len, want); - printf (" want full |%s|\n", want); - printf (" ret %d\n", ret); - printf (" want_len %d\n", want_len); - abort (); - } - } + { + if (memcmp (got, want, got_len) != 0 || got[got_len] != '\0') + { + printf ("gmp_vsnprintf wrong result string\n"); + error: + printf (" fmt |%s|\n", fmt); + printf (" bufsize %u\n", bufsize); + printf (" got |%s|\n", got); + printf (" want |%.*s|\n", got_len, want); + printf (" want full |%s|\n", want); + printf (" ret %d\n", ret); + printf (" want_len %d\n", want_len); + abort (); + } + } } } @@ -267,7 +267,7 @@ check_vasprintf (const char *want, const char *fmt, va_list ap) { char *got; int got_len, want_len; - + want_len = strlen (want); got_len = gmp_vasprintf (&got, fmt, ap); @@ -427,37 +427,37 @@ check_z (void) mp_size_t nsize, zeros; mpz_init (z); - + for (i = 0; i < numberof (data); i++) { mpz_set_str_or_abort (z, data[i].z, 0); /* don't try negatives or forced sign in hex or octal */ if (mpz_fits_slong_p (z) - && ! (hex_or_octal_p (data[i].fmt) - && (strchr (data[i].fmt, '+') != NULL || mpz_sgn(z) < 0))) - { - check_plain (data[i].want, data[i].fmt, mpz_get_si (z)); - } - + && ! (hex_or_octal_p (data[i].fmt) + && (strchr (data[i].fmt, '+') != NULL || mpz_sgn(z) < 0))) + { + check_plain (data[i].want, data[i].fmt, mpz_get_si (z)); + } + check_one (data[i].want, data[i].fmt, z); /* Same again, with %N and possibly some high zero limbs */ nfmt = __gmp_allocate_strdup (data[i].fmt); for (j = 0; nfmt[j] != '\0'; j++) - if (nfmt[j] == 'Z') - nfmt[j] = 'N'; + if (nfmt[j] == 'Z') + nfmt[j] = 'N'; for (zeros = 0; zeros <= 3; zeros++) - { - nsize = ABSIZ(z)+zeros; - MPZ_REALLOC (z, nsize); - nsize = (SIZ(z) >= 0 ? nsize : -nsize); - refmpn_zero (PTR(z)+ABSIZ(z), zeros); - check_one (data[i].want, nfmt, PTR(z), nsize); - } + { + nsize = ABSIZ(z)+zeros; + MPZ_REALLOC (z, nsize); + nsize = (SIZ(z) >= 0 ? nsize : -nsize); + refmpn_zero (PTR(z)+ABSIZ(z), zeros); + check_one (data[i].want, nfmt, PTR(z), nsize); + } __gmp_free_func (nfmt, strlen(nfmt)+1); } - + mpz_clear (z); } @@ -558,13 +558,13 @@ check_q (void) mpq_t q; mpq_init (q); - + for (i = 0; i < numberof (data); i++) { mpq_set_str_or_abort (q, data[i].q, 0); check_one (data[i].want, data[i].fmt, q); } - + mpq_clear (q); } @@ -715,14 +715,14 @@ check_f (void) for (i = 0; i < numberof (data); i++) { if (data[i].f[0] == '0' && data[i].f[1] == 'x') - mpf_set_str_or_abort (f, data[i].f, 16); + mpf_set_str_or_abort (f, data[i].f, 16); else - mpf_set_str_or_abort (f, data[i].f, 10); - + mpf_set_str_or_abort (f, data[i].f, 10); + /* if mpf->double doesn't truncate, then expect same result */ d = mpf_get_d (f); if (mpf_cmp_d (f, d) == 0) - check_plain (data[i].want, data[i].fmt, d); + check_plain (data[i].want, data[i].fmt, d); check_one (data[i].want, data[i].fmt, f); } @@ -793,16 +793,16 @@ check_n (void) do { \ type x[2]; \ char fmt[128]; \ - \ + \ x[0] = ~ (type) 0; \ x[1] = ~ (type) 0; \ sprintf (fmt, "%%d%%%sn%%d", string); \ check_one ("123456", fmt, 123, &x[0], 456); \ - \ + \ /* should write whole of x[0] and none of x[1] */ \ ASSERT_ALWAYS (x[0] == 3); \ ASSERT_ALWAYS (x[1] == (type) ~ (type) 0); \ - \ + \ } while (0) CHECK_N (mp_limb_t, "M"); @@ -875,9 +875,9 @@ check_n (void) MPN_ZERO (a_want, numberof (a_want)); for (i = 1; i < numberof (a); i++) { - check_one ("blah", "bl%Nnah", a, i); - a_want[0] = 2; - ASSERT_ALWAYS (mpn_cmp (a, a_want, i) == 0); + check_one ("blah", "bl%Nnah", a, i); + a_want[0] = 2; + ASSERT_ALWAYS (mpn_cmp (a, a_want, i) == 0); } } } @@ -915,32 +915,32 @@ check_misc (void) /* from the glibc info docs */ mpz_set_si (z, 0L); check_one ("| 0|0 | +0|+0 | 0|00000| | 00|0|", - "|%5Zd|%-5Zd|%+5Zd|%+-5Zd|% 5Zd|%05Zd|%5.0Zd|%5.2Zd|%Zd|", - /**/ z, z, z, z, z, z, z, z, z); + "|%5Zd|%-5Zd|%+5Zd|%+-5Zd|% 5Zd|%05Zd|%5.0Zd|%5.2Zd|%Zd|", + /**/ z, z, z, z, z, z, z, z, z); mpz_set_si (z, 1L); check_one ("| 1|1 | +1|+1 | 1|00001| 1| 01|1|", - "|%5Zd|%-5Zd|%+5Zd|%+-5Zd|% 5Zd|%05Zd|%5.0Zd|%5.2Zd|%Zd|", - /**/ z, z, z, z, z, z, z, z, z); + "|%5Zd|%-5Zd|%+5Zd|%+-5Zd|% 5Zd|%05Zd|%5.0Zd|%5.2Zd|%Zd|", + /**/ z, z, z, z, z, z, z, z, z); mpz_set_si (z, -1L); check_one ("| -1|-1 | -1|-1 | -1|-0001| -1| -01|-1|", - "|%5Zd|%-5Zd|%+5Zd|%+-5Zd|% 5Zd|%05Zd|%5.0Zd|%5.2Zd|%Zd|", - /**/ z, z, z, z, z, z, z, z, z); + "|%5Zd|%-5Zd|%+5Zd|%+-5Zd|% 5Zd|%05Zd|%5.0Zd|%5.2Zd|%Zd|", + /**/ z, z, z, z, z, z, z, z, z); mpz_set_si (z, 100000L); check_one ("|100000|100000|+100000|+100000| 100000|100000|100000|100000|100000|", - "|%5Zd|%-5Zd|%+5Zd|%+-5Zd|% 5Zd|%05Zd|%5.0Zd|%5.2Zd|%Zd|", - /**/ z, z, z, z, z, z, z, z, z); + "|%5Zd|%-5Zd|%+5Zd|%+-5Zd|% 5Zd|%05Zd|%5.0Zd|%5.2Zd|%Zd|", + /**/ z, z, z, z, z, z, z, z, z); mpz_set_si (z, 0L); check_one ("| 0| 0| 0| 0| 0| 0| 00000000|", - "|%5Zo|%5Zx|%5ZX|%#5Zo|%#5Zx|%#5ZX|%#10.8Zx|", - /**/ z, z, z, z, z, z, z); + "|%5Zo|%5Zx|%5ZX|%#5Zo|%#5Zx|%#5ZX|%#10.8Zx|", + /**/ z, z, z, z, z, z, z); mpz_set_si (z, 1L); check_one ("| 1| 1| 1| 01| 0x1| 0X1|0x00000001|", - "|%5Zo|%5Zx|%5ZX|%#5Zo|%#5Zx|%#5ZX|%#10.8Zx|", - /**/ z, z, z, z, z, z, z); + "|%5Zo|%5Zx|%5ZX|%#5Zo|%#5Zx|%#5ZX|%#10.8Zx|", + /**/ z, z, z, z, z, z, z); mpz_set_si (z, 100000L); check_one ("|303240|186a0|186A0|0303240|0x186a0|0X186A0|0x000186a0|", - "|%5Zo|%5Zx|%5ZX|%#5Zo|%#5Zx|%#5ZX|%#10.8Zx|", - /**/ z, z, z, z, z, z, z); + "|%5Zo|%5Zx|%5ZX|%#5Zo|%#5Zx|%#5ZX|%#10.8Zx|", + /**/ z, z, z, z, z, z, z); /* %zd for size_t won't be available on old systems, and running something to see if it works might be bad, so only try it on glibc, and only on a diff --git a/tests/mpbsd/t-itom.c b/tests/mpbsd/t-itom.c index 0e7f8a86e..9b49cb000 100644 --- a/tests/mpbsd/t-itom.c +++ b/tests/mpbsd/t-itom.c @@ -52,11 +52,11 @@ check_data (void) { m = itom (data[i].m); if (m->_mp_size != data[i].want_size - || (m->_mp_size != 0 && m->_mp_d[0] != data[i].want_limb)) - { - printf ("itom wrong on data[%d]\n", i); - abort(); - } + || (m->_mp_size != 0 && m->_mp_d[0] != data[i].want_limb)) + { + printf ("itom wrong on data[%d]\n", i); + abort(); + } mfree (m); } } diff --git a/tests/mpf/t-get_si.c b/tests/mpf/t-get_si.c index aa61b36c5..c5080411d 100644 --- a/tests/mpf/t-get_si.c +++ b/tests/mpf/t-get_si.c @@ -66,17 +66,17 @@ check_data (void) got = mpf_get_si (f); if (got != data[i].want) - { - printf ("mpf_get_si wrong at data[%d]\n", i); - printf (" f \"%s\"\n", data[i].f); - printf (" dec "); mpf_out_str (stdout, 10, 0, f); printf ("\n"); - printf (" hex "); mpf_out_str (stdout, 16, 0, f); printf ("\n"); - printf (" size %ld\n", (long) SIZ(f)); - printf (" exp %ld\n", (long) EXP(f)); - printf (" got %ld (0x%lX)\n", got, got); - printf (" want %ld (0x%lX)\n", data[i].want, data[i].want); - abort(); - } + { + printf ("mpf_get_si wrong at data[%d]\n", i); + printf (" f \"%s\"\n", data[i].f); + printf (" dec "); mpf_out_str (stdout, 10, 0, f); printf ("\n"); + printf (" hex "); mpf_out_str (stdout, 16, 0, f); printf ("\n"); + printf (" size %ld\n", (long) SIZ(f)); + printf (" exp %ld\n", (long) EXP(f)); + printf (" got %ld (0x%lX)\n", got, got); + printf (" want %ld (0x%lX)\n", data[i].want, data[i].want); + abort(); + } } mpf_clear (f); } @@ -121,7 +121,7 @@ void check_limbdata (void) { #define M GMP_NUMB_MAX - + static const struct { mp_exp_t exp; mp_size_t size; @@ -195,16 +195,16 @@ check_limbdata (void) got = mpf_get_si (f); if (got != data[i].want) - { - printf ("mpf_get_si wrong at limb data[%d]\n", i); - mpf_trace (" f", f); - mpn_trace (" d", data[i].d, data[i].size); - printf (" size %ld\n", (long) data[i].size); - printf (" exp %ld\n", (long) data[i].exp); - printf (" got %lu (0x%lX)\n", got, got); - printf (" want %lu (0x%lX)\n", data[i].want, data[i].want); - abort(); - } + { + printf ("mpf_get_si wrong at limb data[%d]\n", i); + mpf_trace (" f", f); + mpn_trace (" d", data[i].d, data[i].size); + printf (" size %ld\n", (long) data[i].size); + printf (" exp %ld\n", (long) data[i].exp); + printf (" got %lu (0x%lX)\n", got, got); + printf (" want %lu (0x%lX)\n", data[i].want, data[i].want); + abort(); + } } } diff --git a/tests/mpf/t-get_ui.c b/tests/mpf/t-get_ui.c index e86805de1..f5795134d 100644 --- a/tests/mpf/t-get_ui.c +++ b/tests/mpf/t-get_ui.c @@ -102,16 +102,16 @@ check_limbdata (void) got = mpf_get_ui (f); if (got != data[i].want) - { - printf ("mpf_get_ui wrong at limb data[%d]\n", i); - mpf_trace (" f", f); - mpn_trace (" d", data[i].d, data[i].size); - printf (" size %ld\n", (long) data[i].size); - printf (" exp %ld\n", (long) data[i].exp); - printf (" got %lu (0x%lX)\n", got, got); - printf (" want %lu (0x%lX)\n", data[i].want, data[i].want); - abort(); - } + { + printf ("mpf_get_ui wrong at limb data[%d]\n", i); + mpf_trace (" f", f); + mpn_trace (" d", data[i].d, data[i].size); + printf (" size %ld\n", (long) data[i].size); + printf (" exp %ld\n", (long) data[i].exp); + printf (" got %lu (0x%lX)\n", got, got); + printf (" want %lu (0x%lX)\n", data[i].want, data[i].want); + abort(); + } } } diff --git a/tests/mpf/t-trunc.c b/tests/mpf/t-trunc.c index 880a14028..30e3703b0 100644 --- a/tests/mpf/t-trunc.c +++ b/tests/mpf/t-trunc.c @@ -55,9 +55,9 @@ check_one (mpf_srcptr src, mpf_srcptr trunc, mpf_srcptr ceil, mpf_srcptr floor) MPF_CHECK_FORMAT (got); \ if (mpf_cmp (got, want) != 0) \ { \ - printf ("%s wrong\n", name); \ - check_print (src, got, want); \ - abort (); \ + printf ("%s wrong\n", name); \ + check_print (src, got, want); \ + abort (); \ } CHECK_SEP ("mpf_trunc", mpf_trunc, trunc); @@ -70,9 +70,9 @@ check_one (mpf_srcptr src, mpf_srcptr trunc, mpf_srcptr ceil, mpf_srcptr floor) MPF_CHECK_FORMAT (got); \ if (mpf_cmp (got, want) != 0) \ { \ - printf ("%s wrong\n", name); \ - check_print (src, got, want); \ - abort (); \ + printf ("%s wrong\n", name); \ + check_print (src, got, want); \ + abort (); \ } CHECK_INPLACE ("mpf_trunc", mpf_trunc, trunc); @@ -138,7 +138,7 @@ check_various (void) mpf_set (ceil, src); mpf_set (floor, src); check_all (src, trunc, ceil, floor); - + /* 1/2^1024, fraction only */ mpf_set_ui (src, 1L); mpf_div_2exp (src, src, 1024L); @@ -154,7 +154,7 @@ check_various (void) mpf_set_si (ceil, 1L); mpf_set_si (floor, 0L); check_all (src, trunc, ceil, floor); - + /* 123+1/2^64 */ mpf_set_ui (src, 1L); mpf_div_2exp (src, src, 64L); diff --git a/tests/mpn/t-hgcd.c b/tests/mpn/t-hgcd.c index f15aa9ea9..94d4ca95a 100644 --- a/tests/mpn/t-hgcd.c +++ b/tests/mpn/t-hgcd.c @@ -49,7 +49,7 @@ struct hgcd_ref { /* Sign here, u and v are stored as absolute values */ int sign; - + mpz_t r[4]; mpz_t u[4]; mpz_t v[4]; @@ -81,7 +81,7 @@ main (int argc, char **argv) for (i = 0; hgcd_values[i].res >= 0; i++) { int res; - + mpz_set_str (op1, hgcd_values[i].a, 0); mpz_set_str (op2, hgcd_values[i].b, 0); @@ -97,7 +97,7 @@ main (int argc, char **argv) abort (); } } - + for (i = 0; i < 15; i++) { /* Generate plain operands with unknown gcd. These types of operands @@ -166,7 +166,7 @@ main (int argc, char **argv) if (mpz_size(op1) > 0) one_test (op1, op2, i); } - + exit (0); } @@ -193,7 +193,7 @@ one_test (mpz_t a, mpz_t b, int i) mp_ptr hgcd_init_tp; mp_ptr qstack_tp; mp_ptr hgcd_tp; - + asize = a->_mp_size; bsize = b->_mp_size; @@ -208,23 +208,23 @@ one_test (mpz_t a, mpz_t b, int i) hgcd_scratch = mpn_hgcd_itch (asize); hgcd_tp = refmpn_malloc_limbs (hgcd_scratch); -#if 0 +#if 0 fprintf (stderr, "one_test: i = %d asize = %d, bsize = %d\n", i, a->_mp_size, b->_mp_size); - + gmp_fprintf (stderr, "one_test: i = %d\n" " a = %Zx\n" " b = %Zx\n", - i, a, b); + i, a, b); #endif hgcd_ref_init (&ref); - + res[0] = hgcd_ref (&ref, a, b); - res[1] = mpn_hgcd (&hgcd, - a->_mp_d, asize, - b->_mp_d, bsize, + res[1] = mpn_hgcd (&hgcd, + a->_mp_d, asize, + b->_mp_d, bsize, "ients, hgcd_tp, hgcd_scratch); @@ -256,7 +256,7 @@ one_test (mpz_t a, mpz_t b, int i) refmpn_free_limbs (qstack_tp); refmpn_free_limbs (hgcd_tp); hgcd_ref_clear (&ref); - + return res[0]; } @@ -282,7 +282,7 @@ hgcd_ref_clear (struct hgcd_ref *hgcd) mpz_clear (hgcd->u[i]); mpz_clear (hgcd->v[i]); } -} +} static int hgcd_ref (struct hgcd_ref *hgcd, const mpz_t a, const mpz_t b) @@ -291,7 +291,7 @@ hgcd_ref (struct hgcd_ref *hgcd, const mpz_t a, const mpz_t b) mpz_t t; mpz_t q; int res; - + if (mpz_size(b) <= M) return 0; @@ -305,7 +305,7 @@ hgcd_ref (struct hgcd_ref *hgcd, const mpz_t a, const mpz_t b) } mpz_set (hgcd->r[0], a); mpz_set (hgcd->r[1], b); - + mpz_set_ui (hgcd->u[0], 1); mpz_set_ui (hgcd->v[0], 0); mpz_set_ui (hgcd->u[1], 0); mpz_set_ui (hgcd->v[1], 1); mpz_set_ui (hgcd->u[2], 1); mpz_set (hgcd->v[2], q); @@ -313,7 +313,7 @@ hgcd_ref (struct hgcd_ref *hgcd, const mpz_t a, const mpz_t b) hgcd->sign = 0; mpz_init (t); - + for (;;) { mpz_fdiv_qr(q, hgcd->r[3], hgcd->r[1], hgcd->r[2]); @@ -323,7 +323,7 @@ hgcd_ref (struct hgcd_ref *hgcd, const mpz_t a, const mpz_t b) mpz_mul (hgcd->v[3], q, hgcd->v[2]); mpz_add (hgcd->v[3], hgcd->v[3], hgcd->v[1]); - + if (mpz_size (hgcd->r[3]) <= M) { #if 0 @@ -347,7 +347,7 @@ hgcd_ref (struct hgcd_ref *hgcd, const mpz_t a, const mpz_t b) } /* Check r1 >= t + r2 */ - mpz_add (t, t, hgcd->r[2]); + mpz_add (t, t, hgcd->r[2]); if (mpz_cmp (hgcd->r[1], t) < 0) { res = 2; break; @@ -402,10 +402,10 @@ hgcd_ref (struct hgcd_ref *hgcd, const mpz_t a, const mpz_t b) mpz_swap (hgcd->v[1], hgcd->v[2]); mpz_swap (hgcd->v[2], hgcd->v[3]); } - + mpz_clear (t); mpz_clear (q); - + return res; } @@ -423,7 +423,7 @@ static int hgcd_ref_equal (const struct hgcd *hgcd, const struct hgcd_ref *ref) { unsigned i; - + if (ref->sign != hgcd->sign) return 0; diff --git a/tests/mpq/t-get_d.c b/tests/mpq/t-get_d.c index 8acb99eda..cae4da93b 100644 --- a/tests/mpq/t-get_d.c +++ b/tests/mpq/t-get_d.c @@ -136,7 +136,7 @@ my_ldexp (double d, int e) } else if (e < 0) { - + if (e <= -16) { d /= 65536.0; @@ -225,35 +225,35 @@ check_onebit (void) mpq_set_ui (q, 1L, 1L); if (exp >= 0) - mpq_mul_2exp (q, q, exp); + mpq_mul_2exp (q, q, exp); else - mpq_div_2exp (q, q, -exp); + mpq_div_2exp (q, q, -exp); want = 1.0; for (l = 0; l < exp; l++) - want *= 2.0; + want *= 2.0; for (l = 0; l > exp; l--) - want /= 2.0; + want /= 2.0; for (neg = 0; neg <= 1; neg++) - { - if (neg) - { - mpq_neg (q, q); - want = -want; - } - - got = mpq_get_d (q); - - if (got != want) - { - printf ("mpq_get_d wrong on %s2**%ld\n", neg ? "-" : "", exp); - mpq_trace (" q ", q); - d_trace (" want ", want); - d_trace (" got ", got); - abort(); - } - } + { + if (neg) + { + mpq_neg (q, q); + want = -want; + } + + got = mpq_get_d (q); + + if (got != want) + { + printf ("mpq_get_d wrong on %s2**%ld\n", neg ? "-" : "", exp); + mpq_trace (" q ", q); + d_trace (" want ", want); + d_trace (" got ", got); + abort(); + } + } } mpq_clear (q); } diff --git a/tests/mpq/t-get_str.c b/tests/mpq/t-get_str.c index 96428f7d8..27566e746 100644 --- a/tests/mpq/t-get_str.c +++ b/tests/mpq/t-get_str.c @@ -30,14 +30,14 @@ check_one (mpq_srcptr q, int base, const char *want) { char *str, *ret; size_t str_alloc; - + MPQ_CHECK_FORMAT (q); mp_trace_base = base; str_alloc = mpz_sizeinbase (mpq_numref(q), ABS(base)) + mpz_sizeinbase (mpq_denref(q), ABS(base)) + 3; - + str = mpq_get_str (NULL, base, q); if (strlen(str)+1 > str_alloc) { @@ -57,9 +57,9 @@ check_one (mpq_srcptr q, int base, const char *want) abort (); } (*__gmp_free_func) (str, strlen (str) + 1); - + str = (char *) (*__gmp_allocate_func) (str_alloc); - + ret = mpq_get_str (str, base, q); if (str != ret) { diff --git a/tests/mpq/t-inp_str.c b/tests/mpq/t-inp_str.c index 3fc15de2c..24d9642dc 100644 --- a/tests/mpq/t-inp_str.c +++ b/tests/mpq/t-inp_str.c @@ -86,72 +86,72 @@ check_data (void) for (i = 0; i < numberof (data); i++) { for (post = 0; post <= 2; post++) - { - mpq_set_str_or_abort (want, data[i].want, 0); - MPQ_CHECK_FORMAT (want); - - fp = fopen (FILENAME, "w+"); - ASSERT_ALWAYS (fp != NULL); - fputs (data[i].inp, fp); - for (j = 0; j < post; j++) - putc (' ', fp); - fflush (fp); - ASSERT_ALWAYS (! ferror(fp)); - - rewind (fp); - got_nread = mpq_inp_str (got, fp, data[i].base); - - if (got_nread != 0) - { - ftell_nread = ftell (fp); - if (got_nread != ftell_nread) - { - printf ("mpq_inp_str nread wrong\n"); - printf (" inp \"%s\"\n", data[i].inp); - printf (" base %d\n", data[i].base); - printf (" got_nread %d\n", got_nread); - printf (" ftell_nread %ld\n", ftell_nread); - abort (); - } - } - - if (post == 0 && data[i].want_nread == strlen(data[i].inp)) - { - int c = getc(fp); - if (c != EOF) - { - printf ("mpq_inp_str didn't read to EOF\n"); - printf (" inp \"%s\"\n", data[i].inp); - printf (" base %d\n", data[i].base); - printf (" c '%c' %#x\n", c, c); - abort (); - } - } - - if (got_nread != data[i].want_nread) - { - printf ("mpq_inp_str nread wrong\n"); - printf (" inp \"%s\"\n", data[i].inp); - printf (" base %d\n", data[i].base); - printf (" got_nread %d\n", got_nread); - printf (" want_nread %d\n", data[i].want_nread); - abort (); - } - - MPQ_CHECK_FORMAT (got); - - if (! mpq_equal (got, want)) - { - printf ("mpq_inp_str wrong result\n"); - printf (" inp \"%s\"\n", data[i].inp); - printf (" base %d\n", data[i].base); - mpq_trace (" got ", got); - mpq_trace (" want", want); - abort (); - } - - ASSERT_ALWAYS (fclose (fp) == 0); - } + { + mpq_set_str_or_abort (want, data[i].want, 0); + MPQ_CHECK_FORMAT (want); + + fp = fopen (FILENAME, "w+"); + ASSERT_ALWAYS (fp != NULL); + fputs (data[i].inp, fp); + for (j = 0; j < post; j++) + putc (' ', fp); + fflush (fp); + ASSERT_ALWAYS (! ferror(fp)); + + rewind (fp); + got_nread = mpq_inp_str (got, fp, data[i].base); + + if (got_nread != 0) + { + ftell_nread = ftell (fp); + if (got_nread != ftell_nread) + { + printf ("mpq_inp_str nread wrong\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" got_nread %d\n", got_nread); + printf (" ftell_nread %ld\n", ftell_nread); + abort (); + } + } + + if (post == 0 && data[i].want_nread == strlen(data[i].inp)) + { + int c = getc(fp); + if (c != EOF) + { + printf ("mpq_inp_str didn't read to EOF\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" c '%c' %#x\n", c, c); + abort (); + } + } + + if (got_nread != data[i].want_nread) + { + printf ("mpq_inp_str nread wrong\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" got_nread %d\n", got_nread); + printf (" want_nread %d\n", data[i].want_nread); + abort (); + } + + MPQ_CHECK_FORMAT (got); + + if (! mpq_equal (got, want)) + { + printf ("mpq_inp_str wrong result\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + mpq_trace (" got ", got); + mpq_trace (" want", want); + abort (); + } + + ASSERT_ALWAYS (fclose (fp) == 0); + } } mpq_clear (got); diff --git a/tests/mpq/t-set_str.c b/tests/mpq/t-set_str.c index dd13a9a22..9f95d263b 100644 --- a/tests/mpq/t-set_str.c +++ b/tests/mpq/t-set_str.c @@ -28,7 +28,7 @@ void check_one (mpq_srcptr want, int base, const char *str) { mpq_t got; - + MPQ_CHECK_FORMAT (want); mp_trace_base = base; diff --git a/tests/mpz/bit.c b/tests/mpz/bit.c index 1e6444f03..9eddbb488 100644 --- a/tests/mpz/bit.c +++ b/tests/mpz/bit.c @@ -51,38 +51,38 @@ check_clr_extend (void) for (i = 1; i < 5; i++) { for (f = 0; f <= 1; f++) - { - /* lots of 1 bits in _mp_d */ - mpz_set_ui (got, 1L); - mpz_mul_2exp (got, got, 10*GMP_NUMB_BITS); - mpz_sub_ui (got, got, 1L); - - /* value -2^(n-1) representing ..11100..00 */ - mpz_set_si (got, -1L); - mpz_mul_2exp (got, got, i*GMP_NUMB_BITS-1); - - /* complement bit n, giving ..11000..00 which is -2^n */ - if (f == 0) - mpz_clrbit (got, i*GMP_NUMB_BITS-1); - else - mpz_combit (got, i*GMP_NUMB_BITS-1); - MPZ_CHECK_FORMAT (got); - - mpz_set_si (want, -1L); - mpz_mul_2exp (want, want, i*GMP_NUMB_BITS); - - if (mpz_cmp (got, want) != 0) - { - if (f == 0) - printf ("mpz_clrbit: "); - else - printf ("mpz_combit: "); - printf ("wrong after extension\n"); - mpz_trace ("got ", got); - mpz_trace ("want", want); - abort (); - } - } + { + /* lots of 1 bits in _mp_d */ + mpz_set_ui (got, 1L); + mpz_mul_2exp (got, got, 10*GMP_NUMB_BITS); + mpz_sub_ui (got, got, 1L); + + /* value -2^(n-1) representing ..11100..00 */ + mpz_set_si (got, -1L); + mpz_mul_2exp (got, got, i*GMP_NUMB_BITS-1); + + /* complement bit n, giving ..11000..00 which is -2^n */ + if (f == 0) + mpz_clrbit (got, i*GMP_NUMB_BITS-1); + else + mpz_combit (got, i*GMP_NUMB_BITS-1); + MPZ_CHECK_FORMAT (got); + + mpz_set_si (want, -1L); + mpz_mul_2exp (want, want, i*GMP_NUMB_BITS); + + if (mpz_cmp (got, want) != 0) + { + if (f == 0) + printf ("mpz_clrbit: "); + else + printf ("mpz_combit: "); + printf ("wrong after extension\n"); + mpz_trace ("got ", got); + mpz_trace ("want", want); + abort (); + } + } } mpz_clear (got); @@ -124,14 +124,14 @@ check_com_negs (void) mpz_combit (got, data[i].bit); if (mpz_cmp (got, want) != 0) - { - printf ("mpz_combit: wrong on neg data[%d]\n", i); - mpz_trace ("inp ", inp); - printf ("bit %lu\n", data[i].bit); - mpz_trace ("got ", got); - mpz_trace ("want", want); - abort (); - } + { + printf ("mpz_combit: wrong on neg data[%d]\n", i); + mpz_trace ("inp ", inp); + printf ("bit %lu\n", data[i].bit); + mpz_trace ("got ", got); + mpz_trace ("want", want); + abort (); + } } mpz_clear (inp); @@ -161,30 +161,30 @@ check_tstbit (void) mpn_random2 (pos+zeros, (mp_size_t) NUM_LIMBS); for (low1 = 0; low1 <= 1; low1++) - { - if (low1) - pos[0] |= 1; - - refmpn_neg_n (neg, pos, (mp_size_t) numberof(neg)); - mpz_set_n (z, neg, (mp_size_t) numberof(neg)); - mpz_neg (z, z); - - for (i = 0; i < numberof(pos)*GMP_NUMB_BITS; i++) - { - got = mpz_tstbit (z, i); - want = refmpn_tstbit (pos, i); - if (got != want) - { - printf ("wrong at bit %lu, with %d zeros\n", i, zeros); - printf ("z neg "); debug_mp (z, -16); - mpz_set_n (z, pos, (mp_size_t) numberof(pos)); - printf ("pos "); debug_mp (z, -16); - mpz_set_n (z, neg, (mp_size_t) numberof(neg)); - printf ("neg "); debug_mp (z, -16); - exit (1); - } - } - } + { + if (low1) + pos[0] |= 1; + + refmpn_neg_n (neg, pos, (mp_size_t) numberof(neg)); + mpz_set_n (z, neg, (mp_size_t) numberof(neg)); + mpz_neg (z, z); + + for (i = 0; i < numberof(pos)*GMP_NUMB_BITS; i++) + { + got = mpz_tstbit (z, i); + want = refmpn_tstbit (pos, i); + if (got != want) + { + printf ("wrong at bit %lu, with %d zeros\n", i, zeros); + printf ("z neg "); debug_mp (z, -16); + mpz_set_n (z, pos, (mp_size_t) numberof(pos)); + printf ("pos "); debug_mp (z, -16); + mpz_set_n (z, neg, (mp_size_t) numberof(neg)); + printf ("neg "); debug_mp (z, -16); + exit (1); + } + } + } } mpz_clear (z); } @@ -202,55 +202,55 @@ check_single (void) for (limb = 0; limb < 4; limb++) { for (offset = (limb==0 ? 0 : -2); offset <= 2; offset++) - { - for (initial = 0; initial >= -1; initial--) - { - mpz_set_si (x, (long) initial); - - bit = (unsigned long) limb*BITS_PER_MP_LIMB + offset; - - mpz_clrbit (x, bit); - MPZ_CHECK_FORMAT (x); - if (mpz_tstbit (x, bit) != 0) - { - printf ("check_single(): expected 0\n"); - abort (); - } - - mpz_setbit (x, bit); - MPZ_CHECK_FORMAT (x); - if (mpz_tstbit (x, bit) != 1) - { - printf ("check_single(): expected 1\n"); - abort (); - } - - mpz_clrbit (x, bit); - MPZ_CHECK_FORMAT (x); - if (mpz_tstbit (x, bit) != 0) - { - printf ("check_single(): expected 0\n"); - abort (); - } - - mpz_combit (x, bit); - MPZ_CHECK_FORMAT (x); - if (mpz_tstbit (x, bit) != 1) - { - printf ("check_single(): expected 1\n"); - abort (); - } - - mpz_combit (x, bit); - MPZ_CHECK_FORMAT (x); - if (mpz_tstbit (x, bit) != 0) - { - printf ("check_single(): expected 0\n"); - abort (); - } - } - } - } + { + for (initial = 0; initial >= -1; initial--) + { + mpz_set_si (x, (long) initial); + + bit = (unsigned long) limb*BITS_PER_MP_LIMB + offset; + + mpz_clrbit (x, bit); + MPZ_CHECK_FORMAT (x); + if (mpz_tstbit (x, bit) != 0) + { + printf ("check_single(): expected 0\n"); + abort (); + } + + mpz_setbit (x, bit); + MPZ_CHECK_FORMAT (x); + if (mpz_tstbit (x, bit) != 1) + { + printf ("check_single(): expected 1\n"); + abort (); + } + + mpz_clrbit (x, bit); + MPZ_CHECK_FORMAT (x); + if (mpz_tstbit (x, bit) != 0) + { + printf ("check_single(): expected 0\n"); + abort (); + } + + mpz_combit (x, bit); + MPZ_CHECK_FORMAT (x); + if (mpz_tstbit (x, bit) != 1) + { + printf ("check_single(): expected 1\n"); + abort (); + } + + mpz_combit (x, bit); + MPZ_CHECK_FORMAT (x); + if (mpz_tstbit (x, bit) != 0) + { + printf ("check_single(): expected 0\n"); + abort (); + } + } + } + } mpz_clear (x); } @@ -371,5 +371,3 @@ main (int argc, char *argv[]) tests_end (); exit (0); } - - diff --git a/tests/mpz/t-bin.c b/tests/mpz/t-bin.c index e6777a35c..6e9a34b80 100644 --- a/tests/mpz/t-bin.c +++ b/tests/mpz/t-bin.c @@ -39,7 +39,7 @@ try_mpz_bin_ui (mpz_srcptr want, mpz_srcptr n, unsigned long k) printf (" k=%lu\n", k); printf (" got="); mpz_out_str (stdout, 10, got); printf ("\n"); printf (" want="); mpz_out_str (stdout, 10, want); printf ("\n"); - abort(); + abort(); } mpz_clear (got); } @@ -60,7 +60,7 @@ try_mpz_bin_uiui (mpz_srcptr want, unsigned long n, unsigned long k) printf (" k=%lu\n", k); printf (" got="); mpz_out_str (stdout, 10, got); printf ("\n"); printf (" want="); mpz_out_str (stdout, 10, want); printf ("\n"); - abort(); + abort(); } mpz_clear (got); } @@ -169,7 +169,7 @@ samples (void) try_mpz_bin_ui (want, n, data[i].k); if (mpz_fits_ulong_p (n)) - try_mpz_bin_uiui (want, mpz_get_ui (n), data[i].k); + try_mpz_bin_uiui (want, mpz_get_ui (n), data[i].k); } mpz_clear (n); diff --git a/tests/mpz/t-cmp_si.c b/tests/mpz/t-cmp_si.c index d12f380fa..25e8a3b38 100644 --- a/tests/mpz/t-cmp_si.c +++ b/tests/mpz/t-cmp_si.c @@ -70,19 +70,19 @@ check_data (void) mpz_set_str_or_abort (bz, data[i].b, 0); if (mpz_fits_slong_p (bz)) - { - b = mpz_get_si (bz); - got = mpz_cmp_si (a, b); - if (SGN (got) != data[i].want) - { - printf ("mpz_cmp_si wrong on data[%d]\n", i); - printf (" a="); mpz_out_str (stdout, 10, a); printf ("\n"); - printf (" b=%ld\n", b); - printf (" got=%d\n", got); - printf (" want=%d\n", data[i].want); - abort(); - } - } + { + b = mpz_get_si (bz); + got = mpz_cmp_si (a, b); + if (SGN (got) != data[i].want) + { + printf ("mpz_cmp_si wrong on data[%d]\n", i); + printf (" a="); mpz_out_str (stdout, 10, a); printf ("\n"); + printf (" b=%ld\n", b); + printf (" got=%d\n", got); + printf (" want=%d\n", data[i].want); + abort(); + } + } } mpz_clear (a); diff --git a/tests/mpz/t-div_2exp.c b/tests/mpz/t-div_2exp.c index fa988fcd6..934ef18e4 100644 --- a/tests/mpz/t-div_2exp.c +++ b/tests/mpz/t-div_2exp.c @@ -50,7 +50,7 @@ check_one (mpz_srcptr a, unsigned long d) } \ else \ fun (dst, src, d); - + for (inplace = 0; inplace <= 1; inplace++) { INPLACE (mpz_fdiv_q_2exp, q, a, d); @@ -59,15 +59,15 @@ check_one (mpz_srcptr a, unsigned long d) mpz_mul_2exp (p, q, d); mpz_add (p, p, r); if (mpz_sgn (r) < 0 || mpz_cmp (r, d2exp) >= 0) - { - printf ("mpz_fdiv_r_2exp result out of range\n"); - goto error; - } + { + printf ("mpz_fdiv_r_2exp result out of range\n"); + goto error; + } if (mpz_cmp (p, a) != 0) - { - printf ("mpz_fdiv_[qr]_2exp doesn't multiply back\n"); - goto error; - } + { + printf ("mpz_fdiv_[qr]_2exp doesn't multiply back\n"); + goto error; + } INPLACE (mpz_cdiv_q_2exp, q, a, d); @@ -76,15 +76,15 @@ check_one (mpz_srcptr a, unsigned long d) mpz_mul_2exp (p, q, d); mpz_add (p, p, r); if (mpz_sgn (r) > 0 || mpz_cmpabs (r, d2exp) >= 0) - { - printf ("mpz_cdiv_r_2exp result out of range\n"); - goto error; - } + { + printf ("mpz_cdiv_r_2exp result out of range\n"); + goto error; + } if (mpz_cmp (p, a) != 0) - { - printf ("mpz_cdiv_[qr]_2exp doesn't multiply back\n"); - goto error; - } + { + printf ("mpz_cdiv_[qr]_2exp doesn't multiply back\n"); + goto error; + } INPLACE (mpz_tdiv_q_2exp, q, a, d); @@ -93,20 +93,20 @@ check_one (mpz_srcptr a, unsigned long d) mpz_mul_2exp (p, q, d); mpz_add (p, p, r); if (mpz_sgn (r) != 0 && mpz_sgn (r) != mpz_sgn (a)) - { - printf ("mpz_tdiv_r_2exp result wrong sign\n"); - goto error; - } + { + printf ("mpz_tdiv_r_2exp result wrong sign\n"); + goto error; + } if (mpz_cmpabs (r, d2exp) >= 0) - { - printf ("mpz_tdiv_r_2exp result out of range\n"); - goto error; - } + { + printf ("mpz_tdiv_r_2exp result out of range\n"); + goto error; + } if (mpz_cmp (p, a) != 0) - { - printf ("mpz_tdiv_[qr]_2exp doesn't multiply back\n"); - goto error; - } + { + printf ("mpz_tdiv_[qr]_2exp doesn't multiply back\n"); + goto error; + } } mpz_clear (d2exp); @@ -173,10 +173,10 @@ check_various (void) mpz_mul_2exp (a, a, n); for (j = 0; j < numberof (table); j++) - { - d = table[j]; - check_all (a, d); - } + { + d = table[j]; + check_all (a, d); + } } mpz_clear (a); diff --git a/tests/mpz/t-export.c b/tests/mpz/t-export.c index 48be9b860..f2fb3bd3a 100644 --- a/tests/mpz/t-export.c +++ b/tests/mpz/t-export.c @@ -54,13 +54,13 @@ check_data (void) { "0x15", 5,1, 1,1, 7, { '\001', '\000', '\001', '\000', '\001' } }, { "0x1FFFFFFFFFFF", 3,1, 2,1, 1, { - '\177','\377', '\177','\377', '\177','\377' } }, + '\177','\377', '\177','\377', '\177','\377' } }, { "0x1FFFFFFFFFFF", 3,1, 2,-1, 1, { - '\377','\177', '\377','\177', '\377','\177' } }, + '\377','\177', '\377','\177', '\377','\177' } }, { "0x7", 3,1, 2,1, 15, { - '\000','\001', '\000','\001', '\000','\001' } }, + '\000','\001', '\000','\001', '\000','\001' } }, { "0x7", 3,1, 2,-1, 15, { - '\001','\000', '\001','\000', '\001','\000' } }, + '\001','\000', '\001','\000', '\001','\000' } }, { "0x24", 3,1, 2,1, 14, { '\000','\002', '\000','\001', '\000','\000' }}, { "0x24", 3,1, 2,-1, 14, { '\002','\000', '\001','\000', '\000','\000' }}, @@ -68,64 +68,64 @@ check_data (void) { "0x24", 3,-1, 2,1, 14, { '\000','\000', '\000','\001', '\000','\002' }}, { "0x123456789ABC", 3,1, 2,1, 0, { - '\022','\064', '\126','\170', '\232','\274' } }, + '\022','\064', '\126','\170', '\232','\274' } }, { "0x123456789ABC", 3,-1, 2,1, 0, { - '\232','\274', '\126','\170', '\022','\064' } }, + '\232','\274', '\126','\170', '\022','\064' } }, { "0x123456789ABC", 3,1, 2,-1, 0, { - '\064','\022', '\170','\126', '\274','\232' } }, + '\064','\022', '\170','\126', '\274','\232' } }, { "0x123456789ABC", 3,-1, 2,-1, 0, { - '\274','\232', '\170','\126', '\064','\022' } }, + '\274','\232', '\170','\126', '\064','\022' } }, { "0x112233445566778899AABBCC", 3,1, 4,1, 0, { '\021','\042','\063','\104', - '\125','\146','\167','\210', - '\231','\252','\273','\314' } }, + '\125','\146','\167','\210', + '\231','\252','\273','\314' } }, { "0x112233445566778899AABBCC", 3,-1, 4,1, 0, { '\231','\252','\273','\314', - '\125','\146','\167','\210', - '\021','\042','\063','\104' } }, + '\125','\146','\167','\210', + '\021','\042','\063','\104' } }, { "0x112233445566778899AABBCC", 3,1, 4,-1, 0, { '\104','\063','\042','\021', - '\210','\167','\146','\125', - '\314','\273','\252','\231' } }, + '\210','\167','\146','\125', + '\314','\273','\252','\231' } }, { "0x112233445566778899AABBCC", 3,-1, 4,-1, 0, { '\314','\273','\252','\231', - '\210','\167','\146','\125', - '\104','\063','\042','\021' } }, + '\210','\167','\146','\125', + '\104','\063','\042','\021' } }, { "0x100120023003400450056006700780089009A00AB00BC00C", 3,1, 8,1, 0, { '\020','\001','\040','\002','\060','\003','\100','\004', - '\120','\005','\140','\006','\160','\007','\200','\010', - '\220','\011','\240','\012','\260','\013','\300','\014' } }, + '\120','\005','\140','\006','\160','\007','\200','\010', + '\220','\011','\240','\012','\260','\013','\300','\014' } }, { "0x100120023003400450056006700780089009A00AB00BC00C", 3,-1, 8,1, 0, { '\220','\011','\240','\012','\260','\013','\300','\014', - '\120','\005','\140','\006','\160','\007','\200','\010', - '\020','\001','\040','\002','\060','\003','\100','\004' } }, + '\120','\005','\140','\006','\160','\007','\200','\010', + '\020','\001','\040','\002','\060','\003','\100','\004' } }, { "0x100120023003400450056006700780089009A00AB00BC00C", 3,1, 8,-1, 0, { '\004','\100','\003','\060','\002','\040','\001','\020', - '\010','\200','\007','\160','\006','\140','\005','\120', - '\014','\300','\013','\260','\012','\240','\011','\220' } }, + '\010','\200','\007','\160','\006','\140','\005','\120', + '\014','\300','\013','\260','\012','\240','\011','\220' } }, { "0x100120023003400450056006700780089009A00AB00BC00C", 3,-1, 8,-1, 0, { '\014','\300','\013','\260','\012','\240','\011','\220', - '\010','\200','\007','\160','\006','\140','\005','\120', - '\004','\100','\003','\060','\002','\040','\001','\020' } }, + '\010','\200','\007','\160','\006','\140','\005','\120', + '\004','\100','\003','\060','\002','\040','\001','\020' } }, { "0x155555555555555555555555", 3,1, 4,1, 1, { '\125','\125','\125','\125', - '\052','\252','\252','\252', - '\125','\125','\125','\125' } }, + '\052','\252','\252','\252', + '\125','\125','\125','\125' } }, { "0x155555555555555555555555", 3,-1, 4,1, 1, { '\125','\125','\125','\125', - '\052','\252','\252','\252', - '\125','\125','\125','\125' } }, + '\052','\252','\252','\252', + '\125','\125','\125','\125' } }, { "0x155555555555555555555555", 3,1, 4,-1, 1, { '\125','\125','\125','\125', - '\252','\252','\252','\052', - '\125','\125','\125','\125' } }, + '\252','\252','\252','\052', + '\125','\125','\125','\125' } }, { "0x155555555555555555555555", 3,-1, 4,-1, 1, { '\125','\125','\125','\125', - '\252','\252','\252','\052', - '\125','\125','\125','\125' } }, + '\252','\252','\252','\052', + '\125','\125','\125','\125' } }, }; char buf[sizeof(data[0].src) + sizeof (mp_limb_t) + 128]; @@ -140,54 +140,54 @@ check_data (void) for (i = 0; i < numberof (data); i++) { for (align = 0; align < sizeof (mp_limb_t); align++) - { - mpz_set_str_or_abort (src, data[i].src, 0); - MPZ_CHECK_FORMAT (src); - got_data = buf + align; - - ASSERT_ALWAYS (data[i].want_count * data[i].size + align - <= sizeof (buf)); - - memset (got_data, '\0', data[i].want_count * data[i].size); - ret = mpz_export (got_data, &got_count, data[i].order, - data[i].size, data[i].endian, data[i].nail, src); - - if (ret != got_data) - { - printf ("return doesn't equal given pointer\n"); - error = 1; - } - if (got_count != data[i].want_count) - { - printf ("wrong count\n"); - error = 1; - } - if (memcmp (got_data, data[i].want_data, got_count * data[i].size) != 0) - { - printf ("wrong result data\n"); - error = 1; - } - if (error) - { - printf (" at data[%d] align=%d\n", i, (int) align); - printf (" src \"%s\"\n", data[i].src); - mpz_trace (" src", src); - printf (" order=%d size=%lu endian=%d nail=%u\n", - data[i].order, - (unsigned long) data[i].size, data[i].endian, data[i].nail); - printf (" want count %lu\n", (unsigned long) data[i].want_count); - printf (" got count %lu\n", (unsigned long) got_count); - printf (" want"); - for (j = 0; j < data[i].want_count*data[i].size; j++) - printf (" 0x%02X,", (unsigned) (unsigned char) data[i].want_data[j]); - printf ("\n"); - printf (" got "); - for (j = 0; j < got_count*data[i].size; j++) - printf (" 0x%02X,", (unsigned) (unsigned char) got_data[j]); - printf ("\n"); - abort (); - } - } + { + mpz_set_str_or_abort (src, data[i].src, 0); + MPZ_CHECK_FORMAT (src); + got_data = buf + align; + + ASSERT_ALWAYS (data[i].want_count * data[i].size + align + <= sizeof (buf)); + + memset (got_data, '\0', data[i].want_count * data[i].size); + ret = mpz_export (got_data, &got_count, data[i].order, + data[i].size, data[i].endian, data[i].nail, src); + + if (ret != got_data) + { + printf ("return doesn't equal given pointer\n"); + error = 1; + } + if (got_count != data[i].want_count) + { + printf ("wrong count\n"); + error = 1; + } + if (memcmp (got_data, data[i].want_data, got_count * data[i].size) != 0) + { + printf ("wrong result data\n"); + error = 1; + } + if (error) + { + printf (" at data[%d] align=%d\n", i, (int) align); + printf (" src \"%s\"\n", data[i].src); + mpz_trace (" src", src); + printf (" order=%d size=%lu endian=%d nail=%u\n", + data[i].order, + (unsigned long) data[i].size, data[i].endian, data[i].nail); + printf (" want count %lu\n", (unsigned long) data[i].want_count); + printf (" got count %lu\n", (unsigned long) got_count); + printf (" want"); + for (j = 0; j < data[i].want_count*data[i].size; j++) + printf (" 0x%02X,", (unsigned) (unsigned char) data[i].want_data[j]); + printf ("\n"); + printf (" got "); + for (j = 0; j < got_count*data[i].size; j++) + printf (" 0x%02X,", (unsigned) (unsigned char) got_data[j]); + printf ("\n"); + abort (); + } + } } mpz_clear (src); } diff --git a/tests/mpz/t-get_si.c b/tests/mpz/t-get_si.c index 182a9ceb5..0a9739bf0 100644 --- a/tests/mpz/t-get_si.c +++ b/tests/mpz/t-get_si.c @@ -51,15 +51,15 @@ check_data (void) got = mpz_get_si (n); if (got != data[i].want) - { - printf ("mpz_get_si wrong at data[%d]\n", i); - printf (" n \"%s\" (", data[i].n); - mpz_out_str (stdout, 10, n); printf (", hex "); - mpz_out_str (stdout, 16, n); printf (")\n"); - printf (" got %ld (0x%lX)\n", got, got); - printf (" want %ld (0x%lX)\n", data[i].want, data[i].want); - abort(); - } + { + printf ("mpz_get_si wrong at data[%d]\n", i); + printf (" n \"%s\" (", data[i].n); + mpz_out_str (stdout, 10, n); printf (", hex "); + mpz_out_str (stdout, 16, n); printf (")\n"); + printf (" got %ld (0x%lX)\n", got, got); + printf (" want %ld (0x%lX)\n", data[i].want, data[i].want); + abort(); + } } mpz_clear (n); } diff --git a/tests/mpz/t-inp_str.c b/tests/mpz/t-inp_str.c index 8d6989d97..7c0893752 100644 --- a/tests/mpz/t-inp_str.c +++ b/tests/mpz/t-inp_str.c @@ -83,92 +83,92 @@ check_data (void) for (i = 0; i < numberof (data); i++) { for (pre = 0; pre <= 3; pre++) - { - for (post = 0; post <= 2; post++) - { - mpz_set_str_or_abort (want, data[i].want, 0); - MPZ_CHECK_FORMAT (want); - - /* create the file new each time to ensure its length is what - we want */ - fp = fopen (FILENAME, "w+"); - ASSERT_ALWAYS (fp != NULL); - for (j = 0; j < pre; j++) - putc (' ', fp); - fputs (data[i].inp, fp); - for (j = 0; j < post; j++) - putc (' ', fp); - fflush (fp); - ASSERT_ALWAYS (! ferror(fp)); - - rewind (fp); - got_nread = mpz_inp_str (got, fp, data[i].base); - - if (got_nread != 0) - { - ftell_nread = ftell (fp); - if (got_nread != ftell_nread) - { - printf ("mpz_inp_str nread wrong\n"); - printf (" inp \"%s\"\n", data[i].inp); - printf (" base %d\n", data[i].base); - printf (" pre %d\n", pre); - printf (" post %d\n", post); - printf (" got_nread %d\n", got_nread); - printf (" ftell_nread %ld\n", ftell_nread); - abort (); - } - } - - /* if data[i].inp is a whole string to read and there's no post - whitespace then expect to have EOF */ - if (post == 0 && data[i].want_nread == strlen(data[i].inp)) - { - int c = getc(fp); - if (c != EOF) - { - printf ("mpz_inp_str didn't read to EOF\n"); - printf (" inp \"%s\"\n", data[i].inp); - printf (" base %d\n", data[i].base); - printf (" pre %d\n", pre); - printf (" post %d\n", post); - printf (" c '%c' %#x\n", c, c); - abort (); - } - } - - /* only expect "pre" included in the count when non-zero */ - want_nread = data[i].want_nread; - if (want_nread != 0) - want_nread += pre; - - if (got_nread != want_nread) - { - printf ("mpz_inp_str nread wrong\n"); - printf (" inp \"%s\"\n", data[i].inp); - printf (" base %d\n", data[i].base); - printf (" pre %d\n", pre); - printf (" post %d\n", post); - printf (" got_nread %d\n", got_nread); - printf (" want_nread %d\n", want_nread); - abort (); - } - - MPZ_CHECK_FORMAT (got); - - if (mpz_cmp (got, want) != 0) - { - printf ("mpz_inp_str wrong result\n"); - printf (" inp \"%s\"\n", data[i].inp); - printf (" base %d\n", data[i].base); - mpz_trace (" got ", got); - mpz_trace (" want", want); - abort (); - } - - ASSERT_ALWAYS (fclose (fp) == 0); - } - } + { + for (post = 0; post <= 2; post++) + { + mpz_set_str_or_abort (want, data[i].want, 0); + MPZ_CHECK_FORMAT (want); + + /* create the file new each time to ensure its length is what + we want */ + fp = fopen (FILENAME, "w+"); + ASSERT_ALWAYS (fp != NULL); + for (j = 0; j < pre; j++) + putc (' ', fp); + fputs (data[i].inp, fp); + for (j = 0; j < post; j++) + putc (' ', fp); + fflush (fp); + ASSERT_ALWAYS (! ferror(fp)); + + rewind (fp); + got_nread = mpz_inp_str (got, fp, data[i].base); + + if (got_nread != 0) + { + ftell_nread = ftell (fp); + if (got_nread != ftell_nread) + { + printf ("mpz_inp_str nread wrong\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" pre %d\n", pre); + printf (" post %d\n", post); + printf (" got_nread %d\n", got_nread); + printf (" ftell_nread %ld\n", ftell_nread); + abort (); + } + } + + /* if data[i].inp is a whole string to read and there's no post + whitespace then expect to have EOF */ + if (post == 0 && data[i].want_nread == strlen(data[i].inp)) + { + int c = getc(fp); + if (c != EOF) + { + printf ("mpz_inp_str didn't read to EOF\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" pre %d\n", pre); + printf (" post %d\n", post); + printf (" c '%c' %#x\n", c, c); + abort (); + } + } + + /* only expect "pre" included in the count when non-zero */ + want_nread = data[i].want_nread; + if (want_nread != 0) + want_nread += pre; + + if (got_nread != want_nread) + { + printf ("mpz_inp_str nread wrong\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + printf (" pre %d\n", pre); + printf (" post %d\n", post); + printf (" got_nread %d\n", got_nread); + printf (" want_nread %d\n", want_nread); + abort (); + } + + MPZ_CHECK_FORMAT (got); + + if (mpz_cmp (got, want) != 0) + { + printf ("mpz_inp_str wrong result\n"); + printf (" inp \"%s\"\n", data[i].inp); + printf (" base %d\n", data[i].base); + mpz_trace (" got ", got); + mpz_trace (" want", want); + abort (); + } + + ASSERT_ALWAYS (fclose (fp) == 0); + } + } } mpz_clear (got); diff --git a/tests/mpz/t-io_raw.c b/tests/mpz/t-io_raw.c index 1284db38b..4fd71e4be 100644 --- a/tests/mpz/t-io_raw.c +++ b/tests/mpz/t-io_raw.c @@ -72,61 +72,61 @@ check_in (void) for (i = 0; i < 32; i++) { for (zeros = 0; zeros < 8; zeros++) - { - for (neg = 0; neg <= 1; neg++) - { - want_ret = i + zeros + 4; - - /* need this to get the twos complement right */ - ASSERT_ALWAYS (sizeof (size) >= 4); - - size = i + zeros; - if (neg) - size = -size; - - fp = fopen_wplusb_or_die (FILENAME); - for (j = 3; j >= 0; j--) - ASSERT_ALWAYS (putc ((size >> (j*8)) & 0xFF, fp) != EOF); - for (j = 0; j < zeros; j++) - ASSERT_ALWAYS (putc ('\0', fp) != EOF); - for (j = 0; j < i; j++) - ASSERT_ALWAYS (putc (BYTEVAL (j), fp) != EOF); - /* and some trailing garbage */ - ASSERT_ALWAYS (putc ('x', fp) != EOF); - ASSERT_ALWAYS (putc ('y', fp) != EOF); - ASSERT_ALWAYS (putc ('z', fp) != EOF); - ASSERT_ALWAYS (fflush (fp) == 0); - rewind (fp); - - got_ret = mpz_inp_raw (got, fp); - ASSERT_ALWAYS (! ferror(fp)); - ASSERT_ALWAYS (fclose (fp) == 0); - - MPZ_CHECK_FORMAT (got); - - if (got_ret != want_ret) - { - printf ("check_in: return value wrong\n"); - error = 1; - } - if (mpz_cmp (got, want) != 0) - { - printf ("check_in: result wrong\n"); - error = 1; - } - if (error) - { - printf (" i=%d zeros=%d neg=%d\n", i, zeros, neg); - printf (" got_ret %lu\n", (unsigned long) got_ret); - printf (" want_ret %lu\n", (unsigned long) want_ret); - mpz_trace (" got ", got); - mpz_trace (" want ", want); - abort (); - } - - mpz_neg (want, want); - } - } + { + for (neg = 0; neg <= 1; neg++) + { + want_ret = i + zeros + 4; + + /* need this to get the twos complement right */ + ASSERT_ALWAYS (sizeof (size) >= 4); + + size = i + zeros; + if (neg) + size = -size; + + fp = fopen_wplusb_or_die (FILENAME); + for (j = 3; j >= 0; j--) + ASSERT_ALWAYS (putc ((size >> (j*8)) & 0xFF, fp) != EOF); + for (j = 0; j < zeros; j++) + ASSERT_ALWAYS (putc ('\0', fp) != EOF); + for (j = 0; j < i; j++) + ASSERT_ALWAYS (putc (BYTEVAL (j), fp) != EOF); + /* and some trailing garbage */ + ASSERT_ALWAYS (putc ('x', fp) != EOF); + ASSERT_ALWAYS (putc ('y', fp) != EOF); + ASSERT_ALWAYS (putc ('z', fp) != EOF); + ASSERT_ALWAYS (fflush (fp) == 0); + rewind (fp); + + got_ret = mpz_inp_raw (got, fp); + ASSERT_ALWAYS (! ferror(fp)); + ASSERT_ALWAYS (fclose (fp) == 0); + + MPZ_CHECK_FORMAT (got); + + if (got_ret != want_ret) + { + printf ("check_in: return value wrong\n"); + error = 1; + } + if (mpz_cmp (got, want) != 0) + { + printf ("check_in: result wrong\n"); + error = 1; + } + if (error) + { + printf (" i=%d zeros=%d neg=%d\n", i, zeros, neg); + printf (" got_ret %lu\n", (unsigned long) got_ret); + printf (" want_ret %lu\n", (unsigned long) want_ret); + mpz_trace (" got ", got); + mpz_trace (" want ", want); + abort (); + } + + mpz_neg (want, want); + } + } mpz_mul_2exp (want, want, 8); mpz_add_ui (want, want, (unsigned long) BYTEVAL (i)); } @@ -151,66 +151,66 @@ check_out (void) for (i = 0; i < 32; i++) { for (neg = 0; neg <= 1; neg++) - { - want_len = i + 4; - - /* need this to get the twos complement right */ - ASSERT_ALWAYS (sizeof (size) >= 4); - - size = i; - if (neg) - size = -size; - - p = want; - for (j = 3; j >= 0; j--) - *p++ = size >> (j*8); - for (j = 0; j < i; j++) - *p++ = BYTEVAL (j); - ASSERT_ALWAYS (p <= want + sizeof (want)); - - fp = fopen_wplusb_or_die (FILENAME); - got_ret = mpz_out_raw (fp, z); - ASSERT_ALWAYS (fflush (fp) == 0); - rewind (fp); - got_read = fread (got, 1, sizeof(got), fp); - ASSERT_ALWAYS (! ferror(fp)); - ASSERT_ALWAYS (fclose (fp) == 0); - - if (got_ret != want_len) - { - printf ("check_out: wrong return value\n"); - error = 1; - } - if (got_read != want_len) - { - printf ("check_out: wrong number of bytes read back\n"); - error = 1; - } - if (memcmp (want, got, want_len) != 0) - { - printf ("check_out: wrong data\n"); - error = 1; - } - if (error) - { - printf (" i=%d neg=%d\n", i, neg); - mpz_trace (" z", z); - printf (" got_ret %lu\n", (unsigned long) got_ret); - printf (" got_read %lu\n", (unsigned long) got_read); - printf (" want_len %lu\n", (unsigned long) want_len); - printf (" want"); - for (j = 0; j < want_len; j++) - printf (" %02X", (unsigned) (unsigned char) want[j]); - printf ("\n"); - printf (" got "); - for (j = 0; j < want_len; j++) - printf (" %02X", (unsigned) (unsigned char) got[j]); - printf ("\n"); - abort (); - } - - mpz_neg (z, z); - } + { + want_len = i + 4; + + /* need this to get the twos complement right */ + ASSERT_ALWAYS (sizeof (size) >= 4); + + size = i; + if (neg) + size = -size; + + p = want; + for (j = 3; j >= 0; j--) + *p++ = size >> (j*8); + for (j = 0; j < i; j++) + *p++ = BYTEVAL (j); + ASSERT_ALWAYS (p <= want + sizeof (want)); + + fp = fopen_wplusb_or_die (FILENAME); + got_ret = mpz_out_raw (fp, z); + ASSERT_ALWAYS (fflush (fp) == 0); + rewind (fp); + got_read = fread (got, 1, sizeof(got), fp); + ASSERT_ALWAYS (! ferror(fp)); + ASSERT_ALWAYS (fclose (fp) == 0); + + if (got_ret != want_len) + { + printf ("check_out: wrong return value\n"); + error = 1; + } + if (got_read != want_len) + { + printf ("check_out: wrong number of bytes read back\n"); + error = 1; + } + if (memcmp (want, got, want_len) != 0) + { + printf ("check_out: wrong data\n"); + error = 1; + } + if (error) + { + printf (" i=%d neg=%d\n", i, neg); + mpz_trace (" z", z); + printf (" got_ret %lu\n", (unsigned long) got_ret); + printf (" got_read %lu\n", (unsigned long) got_read); + printf (" want_len %lu\n", (unsigned long) want_len); + printf (" want"); + for (j = 0; j < want_len; j++) + printf (" %02X", (unsigned) (unsigned char) want[j]); + printf ("\n"); + printf (" got "); + for (j = 0; j < want_len; j++) + printf (" %02X", (unsigned) (unsigned char) got[j]); + printf ("\n"); + abort (); + } + + mpz_neg (z, z); + } mpz_mul_2exp (z, z, 8); mpz_add_ui (z, z, (unsigned long) BYTEVAL (i)); } @@ -246,23 +246,23 @@ check_rand (void) MPZ_CHECK_FORMAT (got); if (inp_ret != out_ret) - { - printf ("check_rand: different inp/out return values\n"); - error = 1; - } + { + printf ("check_rand: different inp/out return values\n"); + error = 1; + } if (mpz_cmp (got, want) != 0) - { - printf ("check_rand: wrong result\n"); - error = 1; - } + { + printf ("check_rand: wrong result\n"); + error = 1; + } if (error) - { - printf (" out_ret %lu\n", (unsigned long) out_ret); - printf (" inp_ret %lu\n", (unsigned long) inp_ret); - mpz_trace (" want", want); - mpz_trace (" got ", got); - abort (); - } + { + printf (" out_ret %lu\n", (unsigned long) out_ret); + printf (" inp_ret %lu\n", (unsigned long) inp_ret); + mpz_trace (" want", want); + mpz_trace (" got ", got); + abort (); + } } mpz_clear (got); diff --git a/tests/mpz/t-jac.c b/tests/mpz/t-jac.c index ba113f476..1b3e09288 100644 --- a/tests/mpz/t-jac.c +++ b/tests/mpz/t-jac.c @@ -23,7 +23,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ To check the test data against PARI-GP, run - t-jac -p | gp -q + t-jac -p | gp -q It takes a while because the output from "t-jac -p" is big. @@ -93,8 +93,8 @@ try_base (mp_limb_t a, mp_limb_t b, int answer) if (got != answer) { printf (LL("mpn_jacobi_base (%lu, %lu) is %d should be %d\n", - "mpn_jacobi_base (%llu, %llu) is %d should be %d\n"), - a, b, got, answer); + "mpn_jacobi_base (%llu, %llu) is %d should be %d\n"), + a, b, got, answer); abort (); } } @@ -176,7 +176,7 @@ try_zi_zi (mpz_srcptr a, mpz_srcptr b, int answer) if (got != answer) { printf ("mpz_kronecker ("); - mpz_out_str (stdout, 10, a); + mpz_out_str (stdout, 10, a); printf (", "); mpz_out_str (stdout, 10, b); printf (") is %d should be %d\n", got, answer); @@ -189,9 +189,9 @@ void try_pari (mpz_srcptr a, mpz_srcptr b, int answer) { printf ("try("); - mpz_out_str (stdout, 10, a); + mpz_out_str (stdout, 10, a); printf (","); - mpz_out_str (stdout, 10, b); + mpz_out_str (stdout, 10, b); printf (",%d)\n", answer); } @@ -221,7 +221,7 @@ try_each (mpz_srcptr a, mpz_srcptr b, int answer) try_si_zi (mpz_get_si (a), b, answer); try_zi_zi (a, b, answer); -} +} /* Try (a/b) and (a/-b). */ @@ -287,11 +287,11 @@ try_periodic_num (mpz_srcptr a_orig, mpz_srcptr b, int answer) /* Try (a/b+k*p) for various k, using the fact (a/b) is periodic in b of period p. - period p - a==0,1mod4 a - a==2mod4 4*a - a==3mod4 and b odd 4*a - a==3mod4 and b even 8*a + period p + a==0,1mod4 a + a==2mod4 4*a + a==3mod4 and b odd 4*a + a==3mod4 and b even 8*a In Henri Cohen's book the period is given as 4*a for all a==2,3mod4, but a counterexample would seem to be (3/2)=-1 which with (3/14)=+1 doesn't @@ -365,8 +365,8 @@ try_2den (mpz_srcptr a, mpz_srcptr b_orig, int answer) /* (a/2) is 0 if a even, 1 if a==1 or 7 mod 8, -1 if a==3 or 5 mod 8 */ answer_a2 = (mpz_even_p (a) ? 0 - : (((SIZ(a) >= 0 ? PTR(a)[0] : -PTR(a)[0]) + 2) & 7) < 4 ? 1 - : -1); + : (((SIZ(a) >= 0 ? PTR(a)[0] : -PTR(a)[0]) + 2) & 7) < 4 ? 1 + : -1); for (kindex = 0; kindex < numberof (ktable); kindex++) { @@ -374,8 +374,8 @@ try_2den (mpz_srcptr a, mpz_srcptr b_orig, int answer) /* answer_k = answer*(answer_a2^k) */ answer_k = (answer_a2 == 0 && k != 0 ? 0 - : (k & 1) == 1 && answer_a2 == -1 ? -answer - : answer); + : (k & 1) == 1 && answer_a2 == -1 ? -answer + : answer); mpz_mul_2exp (b, b_orig, k); try_pn (a, b, answer_k); @@ -403,8 +403,8 @@ try_2num (mpz_srcptr a_orig, mpz_srcptr b, int answer) /* (2/b) is 0 if b even, 1 if b==1 or 7 mod 8, -1 if b==3 or 5 mod 8 */ answer_2b = (mpz_even_p (b) ? 0 - : (((SIZ(b) >= 0 ? PTR(b)[0] : -PTR(b)[0]) + 2) & 7) < 4 ? 1 - : -1); + : (((SIZ(b) >= 0 ? PTR(b)[0] : -PTR(b)[0]) + 2) & 7) < 4 ? 1 + : -1); for (kindex = 0; kindex < numberof (ktable); kindex++) { @@ -412,10 +412,10 @@ try_2num (mpz_srcptr a_orig, mpz_srcptr b, int answer) /* answer_k = answer*(answer_2b^k) */ answer_k = (answer_2b == 0 && k != 0 ? 0 - : (k & 1) == 1 && answer_2b == -1 ? -answer - : answer); + : (k & 1) == 1 && answer_2b == -1 ? -answer + : answer); - mpz_mul_2exp (a, a_orig, k); + mpz_mul_2exp (a, a_orig, k); try_pn (a, b, answer_k); } @@ -460,7 +460,7 @@ check_data (void) { "5", "0", 0 }, { "24", "60", 0 }, - /* (a/1) = 1, any a + /* (a/1) = 1, any a In particular note (0/1)=1 so that (a/b)=(a mod b/b). */ { "0", "1", 1 }, { "1", "1", 1 }, @@ -727,7 +727,7 @@ main (int argc, char *argv[]) if (argc >= 2 && strcmp (argv[1], "-p") == 0) { option_pari = 1; - + printf ("\ try(a,b,answer) =\n\ {\n\ diff --git a/tests/mpz/t-mul_i.c b/tests/mpz/t-mul_i.c index 2773fcbfd..bf95a153a 100644 --- a/tests/mpz/t-mul_i.c +++ b/tests/mpz/t-mul_i.c @@ -94,7 +94,7 @@ check_samples (void) { unsigned long y; - + mpz_set_ui (x, 1L); y = 0; mpz_mul_ui (got, x, y); diff --git a/tests/mpz/t-oddeven.c b/tests/mpz/t-oddeven.c index b8754c55c..09e2c9387 100644 --- a/tests/mpz/t-oddeven.c +++ b/tests/mpz/t-oddeven.c @@ -61,16 +61,16 @@ check_data (void) mpz_set_str_or_abort (n, data[i].n, 0); if ((mpz_odd_p (n) != 0) != data[i].odd) - { - printf ("mpz_odd_p wrong on data[%d]\n", i); - abort(); - } + { + printf ("mpz_odd_p wrong on data[%d]\n", i); + abort(); + } if ((mpz_even_p (n) != 0) != data[i].even) - { - printf ("mpz_even_p wrong on data[%d]\n", i); - abort(); - } + { + printf ("mpz_even_p wrong on data[%d]\n", i); + abort(); + } } mpz_clear (n); diff --git a/tests/mpz/t-popcount.c b/tests/mpz/t-popcount.c index bab1d21f4..da7487d60 100644 --- a/tests/mpz/t-popcount.c +++ b/tests/mpz/t-popcount.c @@ -37,11 +37,11 @@ check_onebit (void) mpz_setbit (n, i); got = mpz_popcount (n); if (got != 1) - { - printf ("mpz_popcount wrong on single bit at %lu\n", i); - printf (" got %lu, want 1\n", got); - abort(); - } + { + printf ("mpz_popcount wrong on single bit at %lu\n", i); + printf (" got %lu, want 1\n", got); + abort(); + } mpz_clrbit (n, i); } mpz_clear (n); @@ -77,15 +77,15 @@ check_data (void) mpz_set_str_or_abort (n, data[i].n, 0); got = mpz_popcount (n); if (got != data[i].want) - { - printf ("mpz_popcount wrong at data[%d]\n", i); - printf (" n \"%s\"\n", data[i].n); - printf (" "); mpz_out_str (stdout, 10, n); printf ("\n"); - printf (" 0x"); mpz_out_str (stdout, 16, n); printf ("\n"); - printf (" got %lu\n", got); - printf (" want %lu\n", data[i].want); - abort(); - } + { + printf ("mpz_popcount wrong at data[%d]\n", i); + printf (" n \"%s\"\n", data[i].n); + printf (" "); mpz_out_str (stdout, 10, n); printf ("\n"); + printf (" 0x"); mpz_out_str (stdout, 16, n); printf ("\n"); + printf (" got %lu\n", got); + printf (" want %lu\n", data[i].want); + abort(); + } } mpz_clear (n); } @@ -142,12 +142,12 @@ check_random (void) ref = refmpz_popcount (arg); if (got != ref) { - printf ("mpz_popcount wrong on random\n"); - printf (" "); mpz_out_str (stdout, 10, arg); printf ("\n"); - printf (" 0x"); mpz_out_str (stdout, 16, arg); printf ("\n"); - printf (" got %lu\n", got); - printf (" want %lu\n", ref); - abort(); + printf ("mpz_popcount wrong on random\n"); + printf (" "); mpz_out_str (stdout, 10, arg); printf ("\n"); + printf (" 0x"); mpz_out_str (stdout, 16, arg); printf ("\n"); + printf (" got %lu\n", got); + printf (" want %lu\n", ref); + abort(); abort (); } } diff --git a/tests/mpz/t-pow.c b/tests/mpz/t-pow.c index 06534dbfd..75d02fd2e 100644 --- a/tests/mpz/t-pow.c +++ b/tests/mpz/t-pow.c @@ -60,14 +60,14 @@ check_one (mpz_srcptr want, mpz_srcptr base, unsigned long exp) unsigned long base_u = mpz_get_ui (base); mpz_ui_pow_ui (got, base_u, exp); if (mpz_cmp (got, want)) - { - printf ("mpz_ui_pow_ui wrong\n"); - printf (" base=%lu (0x%lX)\n", base_u, base_u); - printf (" exp = %lu (0x%lX)\n", exp, exp); - mpz_trace (" got ", got); - mpz_trace (" want", want); - abort (); - } + { + printf ("mpz_ui_pow_ui wrong\n"); + printf (" base=%lu (0x%lX)\n", base_u, base_u); + printf (" exp = %lu (0x%lX)\n", exp, exp); + mpz_trace (" got ", got); + mpz_trace (" want", want); + abort (); + } } mpz_clear (got); @@ -163,7 +163,7 @@ check_random (int reps) int i; unsigned long size_range, exp; gmp_randstate_ptr rands = RANDS; - + mpz_init (base); mpz_init (want); diff --git a/tests/mpz/t-set_f.c b/tests/mpz/t-set_f.c index 26b099d5a..764006fd3 100644 --- a/tests/mpz/t-set_f.c +++ b/tests/mpz/t-set_f.c @@ -42,44 +42,44 @@ check_one (mpz_srcptr z) for (sh = 0; sh < numberof(shift); sh++) { for (shneg = 0; shneg <= 1; shneg++) - { - for (neg = 0; neg <= 1; neg++) - { - mpf_set_z (f, z); - mpz_set (want, z); - - if (neg) - { - mpf_neg (f, f); - mpz_neg (want, want); - } - - if (shneg) - { - mpz_tdiv_q_2exp (want, want, shift[sh]); - mpf_div_2exp (f, f, shift[sh]); - } - else - { - mpz_mul_2exp (want, want, shift[sh]); - mpf_mul_2exp (f, f, shift[sh]); - } - - mpz_set_f (got, f); - MPZ_CHECK_FORMAT (got); - - if (mpz_cmp (got, want) != 0) - { - printf ("wrong result\n"); - printf (" shift %d\n", shneg ? -shift[sh] : shift[sh]); - printf (" neg %d\n", neg); - mpf_trace (" f", f); - mpz_trace (" got", got); - mpz_trace (" want", want); - abort (); - } - } - } + { + for (neg = 0; neg <= 1; neg++) + { + mpf_set_z (f, z); + mpz_set (want, z); + + if (neg) + { + mpf_neg (f, f); + mpz_neg (want, want); + } + + if (shneg) + { + mpz_tdiv_q_2exp (want, want, shift[sh]); + mpf_div_2exp (f, f, shift[sh]); + } + else + { + mpz_mul_2exp (want, want, shift[sh]); + mpf_mul_2exp (f, f, shift[sh]); + } + + mpz_set_f (got, f); + MPZ_CHECK_FORMAT (got); + + if (mpz_cmp (got, want) != 0) + { + printf ("wrong result\n"); + printf (" shift %d\n", shneg ? -shift[sh] : shift[sh]); + printf (" neg %d\n", neg); + mpf_trace (" f", f); + mpz_trace (" got", got); + mpz_trace (" want", want); + abort (); + } + } + } } mpf_clear (f); diff --git a/tests/mpz/t-set_str.c b/tests/mpz/t-set_str.c index 8571e532c..cb589ca9d 100644 --- a/tests/mpz/t-set_str.c +++ b/tests/mpz/t-set_str.c @@ -28,7 +28,7 @@ void check_one (mpz_srcptr want, int base, const char *str) { mpz_t got; - + MPZ_CHECK_FORMAT (want); mp_trace_base = (base == 0 ? 16 : base); diff --git a/tests/rand/findlc.c b/tests/rand/findlc.c index cb9342bb8..15b3458fd 100644 --- a/tests/rand/findlc.c +++ b/tests/rand/findlc.c @@ -103,7 +103,7 @@ main (int argc, char *argv[]) unsigned long int m2exp; #define DIMS 6 /* dimensions run in spectral test */ mpf_t v[DIMS-1]; /* spectral test result (there's no v - for 1st dimension */ + for 1st dimension */ mpf_t f_merit, low_merit, high_merit; mpz_t acc, minus8; mpz_t min, max; @@ -190,7 +190,7 @@ main (int argc, char *argv[]) mpz_setbit (s, 0); /* Make it odd. */ v_best = m_best = 2*(DIMS-1); - for (;;) + for (;;) { mpz_add (acc, acc, s); mpz_mod_2exp (acc, acc, m2exp); @@ -211,7 +211,7 @@ main (int argc, char *argv[]) if (mpf_cmp_ui (v[f], 1 << (30 / (f + 2) + (f == 2))) < 0) v_lose++; - + if (mpf_cmp (f_merit, low_merit) < 0) m_lose++; diff --git a/tests/rand/gen.c b/tests/rand/gen.c index ea108af30..c3f8c616a 100644 --- a/tests/rand/gen.c +++ b/tests/rand/gen.c @@ -156,7 +156,7 @@ int main (argc, argv) #else ul_adder = (unsigned long int) atoi (str_adder); #endif - + if (mpz_init_set_str (z_a, str_a, 0)) { fprintf (stderr, "gen: bad LC scheme parameter `a': %s\n", str_a); @@ -469,7 +469,7 @@ int main (argc, argv) break; } mpf_clear (f1); - mpf_clear (f_xf); + mpf_clear (f_xf); mpf_clear (f_xt); mpz_clear (z1); mpz_clear (z_seed); diff --git a/tests/rand/spect.c b/tests/rand/spect.c index a9a95a815..f6f872b09 100644 --- a/tests/rand/spect.c +++ b/tests/rand/spect.c @@ -126,7 +126,7 @@ main (int argc, char *argv[]) } -void +void debug_foo() { if (0) diff --git a/tests/rand/stat.c b/tests/rand/stat.c index d71625cc5..e6917d935 100644 --- a/tests/rand/stat.c +++ b/tests/rand/stat.c @@ -24,7 +24,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ Test 1000 real numbers. $ gen 30000 | stat -2 1000 -Test 1000 real numbers 30 times and then test the 30 results in a +Test 1000 real numbers 30 times and then test the 30 results in a ``second level''. $ gen -f mpz_urandomb 1000 | stat -i 0xffffffff @@ -62,7 +62,7 @@ print_ks_results (mpf_t f_p, mpf_t f_p_prob, m = mpf_get_d (f_m); pp = mpf_get_d (f_p_prob); mp = mpf_get_d (f_m_prob); - + fprintf (fp, "%.4f (%.0f%%)\t", p, pp * 100.0); fprintf (fp, "%.4f (%.0f%%)\n", m, mp * 100.0); } @@ -117,7 +117,7 @@ f_freq (const unsigned l1runs, const unsigned l2runs, mpf_init (f_p); mpf_init (f_m); mpf_init (f_p_prob); mpf_init (f_m_prob); - + /* Allocate space for 1st level results. */ l1res = (mpf_t *) malloc (l2runs * 2 * sizeof (mpf_t)); if (NULL == l1res) @@ -125,7 +125,7 @@ f_freq (const unsigned l1runs, const unsigned l2runs, fprintf (stderr, "stat: malloc failure\n"); exit (1); } - + printf ("\nEquidistribution/Frequency test on real numbers (0<=X<1):\n"); printf ("\tKp\t\tKm\n"); @@ -177,7 +177,7 @@ f_freq (const unsigned l1runs, const unsigned l2runs, mpf_clear (f_p); mpf_clear (f_m); mpf_clear (f_p_prob); mpf_clear (f_m_prob); free (l1res); -} +} /* z_freq(l1runs, l2runs, zvec, n, max) -- frequency test on integers 0<=z<=MAX */ @@ -201,13 +201,13 @@ z_freq (const unsigned l1runs, d_V = mpf_get_d (V); printf ("V = %.2f (n = %lu)\n", d_V, n); - + mpf_clear (V); } unsigned int stat_debug = 0; -int +int main (argc, argv) int argc; char *argv[]; @@ -221,7 +221,7 @@ main (argc, argv) " -r max input is real numbers 0 <= R < 1 and use MAX as\n" \ " maximum value when converting real numbers to integers\n" \ ""; - + mpf_t fvec[FVECSIZ]; mpz_t zvec[FVECSIZ]; unsigned long int f, n, vecentries; @@ -235,11 +235,11 @@ main (argc, argv) l2runs = 1; /* 2nd level runs */ mpf_t f_temp; mpz_t z_imax; /* max value when converting between - real number and integer. */ + real number and integer. */ mpf_t f_imax_plus1; /* f_imax + 1 stored in an mpf_t for - convenience */ + convenience */ mpf_t f_imax_minus1; /* f_imax - 1 stored in an mpf_t for - convenience */ + convenience */ mpf_init (f_temp); @@ -297,7 +297,7 @@ main (argc, argv) if (argc < 1) fp = stdin; else - filen = argv[0]; + filen = argv[0]; if (fp != stdin) if (NULL == (fp = fopen (filen, "r"))) @@ -327,7 +327,7 @@ main (argc, argv) if (!mpz_inp_str (zvec[f], fp, 10)) break; } - } + } vecentries = n = f; /* number of entries read */ fclose (fp); @@ -359,7 +359,7 @@ main (argc, argv) } else /* integer input; fill fvec[] */ { - /* mpf_set_z (f_imax_minus1, z_imax); + /* mpf_set_z (f_imax_minus1, z_imax); mpf_sub_ui (f_imax_minus1, f_imax_minus1, 1);*/ for (f = 0; f < n; f++) { @@ -373,7 +373,7 @@ main (argc, argv) } } } - + /* 2 levels? */ if (1 != l2runs) { @@ -394,7 +394,7 @@ main (argc, argv) z_freq (l1runs, l2runs, zvec, n, mpz_get_ui (z_imax)); #endif - mpf_clear (f_temp); mpz_clear (z_imax); + mpf_clear (f_temp); mpz_clear (z_imax); mpf_clear (f_imax_plus1); mpf_clear (f_imax_minus1); for (f = 0; f < vecentries; f++) @@ -405,8 +405,3 @@ main (argc, argv) return 0; } - - - - - diff --git a/tests/rand/statlib.c b/tests/rand/statlib.c index 80ca00608..e429ad6fc 100644 --- a/tests/rand/statlib.c +++ b/tests/rand/statlib.c @@ -62,7 +62,7 @@ for (each observation Xj) rp = max (rp, j/n - b[k]) Kp = sqr (n) * rp -Km = sqr (n) * rm +Km = sqr (n) * rm */ @@ -94,15 +94,15 @@ ks (mpf_t Kp, mpf_t f_jnq; /* j/n or (j-1)/n */ unsigned long int j; - /* Sort the vector in ascending order. */ + /* Sort the vector in ascending order. */ qsort (X, n, sizeof (__mpf_struct), mpf_cmp); /* K-S test. */ - /* Kp = sqr(n) * max(j/n - F(Xj)) for all 1<=j<=n + /* Kp = sqr(n) * max(j/n - F(Xj)) for all 1<=j<=n Km = sqr(n) * max(F(Xj) - (j-1)/n)) for all 1<=j<=n */ - mpf_init (Kt); mpf_init (f_x); mpf_init (f_j); mpf_init (f_jnq); + mpf_init (Kt); mpf_init (f_x); mpf_init (f_j); mpf_init (f_jnq); mpf_set_ui (Kp, 0); mpf_set_ui (Km, 0); for (j = 1; j <= n; j++) { @@ -140,7 +140,7 @@ ks (mpf_t Kp, mpf_mul (Kp, Kp, Kt); mpf_mul (Km, Km, Kt); - mpf_clear (Kt); mpf_clear (f_x); mpf_clear (f_j); mpf_clear (f_jnq); + mpf_clear (Kt); mpf_clear (f_x); mpf_clear (f_j); mpf_clear (f_jnq); } /* ks_table(val, n) -- calculate probability for Kp/Km less than or @@ -175,7 +175,7 @@ ks_table (mpf_t p, mpf_t val, const unsigned int n) #else /* hmmm, gmp doesn't have pow() for floats. use doubles. */ mpf_set_d (t2, pow (M_E, -(2 * pow (mpf_get_d (val), 2)))); -#endif +#endif /* p = 1 - t1 * t2 */ mpf_mul (t1, t1, t2); @@ -204,7 +204,7 @@ x2_table (double t[], /* value = v + sqrt(2*v) * X[p] + (2/3) * X[p]^2 - 2/3 + O(1/sqrt(t) */ /* NOTE: The O() term is ignored for simplicity. */ - + for (f = 0; f < 7; f++) t[f] = v + @@ -218,7 +218,7 @@ being greater than or equal to any number in the sequence. For a random real number between zero and one given by a uniformly distributed random number generator, this is simply equal to X. */ -static void +static void P (mpf_t p, mpf_t x) { mpf_set (p, x); @@ -279,7 +279,7 @@ x2 (mpf_t V, /* result */ fprintf (stderr, "\n"); mpf_div_ui (V, V, n); mpf_sub_ui (V, V, n); - + mpf_clear (f_t); mpf_clear (f_t2); } @@ -361,14 +361,14 @@ mpz_freqt (mpf_t V, /* debug dummy to drag in dump funcs */ void -foo_debug () +foo_debug () { if (0) { - mpf_dump (0); + mpf_dump (0); #ifndef OLDGMP mpz_dump (0); -#endif +#endif } } @@ -385,7 +385,7 @@ merit (mpf_t rop, unsigned int t, mpf_t v, mpz_t m) mpf_set_z (f_m, m); mpf_init_set_d (f_const, M_PI); mpf_init_set_d (f_pi, M_PI); - + switch (t) { case 2: /* PI */ @@ -432,7 +432,7 @@ merit_u (unsigned int t, mpf_t v, mpz_t m) { mpf_t rop; double res; - + mpf_init (rop); merit (rop, t, v, m); res = mpf_get_d (rop); @@ -530,7 +530,7 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) /* S1 [Initialize.] */ ui_t = 2 - 1; /* NOTE: `t' in description == ui_t + 1 - for easy indexing */ + for easy indexing */ mpz_set (h, a); mpz_set (hp, m); mpz_set_ui (p, 1); @@ -582,7 +582,7 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) mpz_mul (tmp1, q, p); mpz_sub (v, pp, tmp1); /* v = pp - q*p */ - + mpz_pow_ui (tmp1, u, 2); mpz_pow_ui (tmp2, v, 2); mpz_add (tmp1, tmp1, tmp2); @@ -613,13 +613,13 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) } mpf_set_z (f_tmp1, s); mpf_sqrt (rop[ui_t - 1], f_tmp1); - + /* S4 [Advance t.] */ mpz_neg (U[0][0], h); mpz_set (U[0][1], p); mpz_neg (U[1][0], hp); mpz_set (U[1][1], pp); - + mpz_set (V[0][0], pp); mpz_set (V[0][1], hp); mpz_neg (V[1][0], p); @@ -645,7 +645,7 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) mpz_set_ui (U[ui_t][ui_t], 1); /* U: Last col in new row. */ mpz_set (V[ui_t][ui_t], m); /* V: Last col in new row. */ - + /* "Finally, for 1 <= i < t, set q = round (vi1 * r / m), vit = vi1*r - q*m, @@ -676,7 +676,7 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) /* S5 [Transform.] */ if (g_debug > DEBUG_2) printf ("(t, k, j, q1, q2, ...)\n"); - do + do { if (g_debug > DEBUG_2) printf ("(%u, %u, %u", ui_t + 1, ui_k + 1, ui_j + 1); @@ -706,7 +706,7 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) mpz_mul (tmp1, q, U[ui_i][ui_l]); mpz_add (U[ui_j][ui_l], U[ui_j][ui_l], tmp1); /* Uj=Uj+q*Ui */ } - + vz_dot (tmp1, U[ui_j], U[ui_j], ui_t + 1); /* tmp1=dot(Uj,Uj) */ if (mpz_cmp (tmp1, s) < 0) /* s = min(s,dot(Uj,Uj)) */ mpz_set (s, tmp1); @@ -761,7 +761,7 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) } /* S8 [Advance X[k].] */ - do + do { if (g_debug > DEBUG_2) { @@ -772,7 +772,7 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) printf ("\n"); fflush (stdout); } - + if (mpz_cmp (X[ui_k], Z[ui_k])) { mpz_add_ui (X[ui_k], X[ui_k], 1); @@ -835,4 +835,3 @@ spectral_test (mpf_t rop[], unsigned int T, mpz_t a, mpz_t m) return; } - diff --git a/tests/rand/t-rand.c b/tests/rand/t-rand.c index 717c572e6..d3e3c252f 100644 --- a/tests/rand/t-rand.c +++ b/tests/rand/t-rand.c @@ -25,7 +25,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #define SEED 1 #define BASE 16 #define ENTS 10 /* Number of entries in array when - printing. */ + printing. */ /* These were generated by this very program. Do not edit! */ /* Integers. */ @@ -126,9 +126,9 @@ static struct rt farr[] = {f128, 128}, {NULL, 0} }; - -int + +int #if __STDC__ main (int argc, char *argv[]) #else @@ -168,7 +168,7 @@ usage: t-rand [function nbits]\n\ } mpz_init (rz); - + if (verify_mode_flag) { #ifdef VERBOSE @@ -190,7 +190,7 @@ usage: t-rand [function nbits]\n\ mpz_set_str (z, a->s[i], BASE); if (mpz_cmp (z, rz) != 0) { - printf ("z%d: ", a->nbits); + printf ("z%d: ", a->nbits); mpz_out_str (stdout, BASE, rz); printf (" should be "); mpz_out_str (stdout, BASE, z); @@ -222,7 +222,7 @@ usage: t-rand [function nbits]\n\ mpf_set_str (f, a->s[i], BASE); if (mpf_cmp (f, rf) != 0) { - printf ("f%d: ", a->nbits); + printf ("f%d: ", a->nbits); mpf_out_str (stdout, BASE, a->nbits, rf); printf (" should be "); mpf_out_str (stdout, BASE, a->nbits, f); @@ -289,7 +289,7 @@ usage: t-rand [function nbits]\n\ gmp_randclear (rstate); } - + mpz_clear (rz); return 0; diff --git a/tests/refmpz.c b/tests/refmpz.c index b86833ed8..b21b5b9fe 100644 --- a/tests/refmpz.c +++ b/tests/refmpz.c @@ -29,7 +29,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ /* Change this to "#define TRACE(x) x" for some traces. */ -#define TRACE(x) +#define TRACE(x) /* FIXME: Shouldn't use plain mpz functions in a reference routine. */ @@ -144,29 +144,29 @@ refmpz_kronecker (mpz_srcptr a_orig, mpz_srcptr b_orig) ASSERT (mpz_sgn (b) > 0); TRACE (printf ("top\n"); - mpz_trace (" a", a); - mpz_trace (" b", b)); + mpz_trace (" a", a); + mpz_trace (" b", b)); if (mpz_cmp (a, b) < 0) - { - TRACE (printf ("swap\n")); - mpz_swap (a, b); - result_bit1 ^= JACOBI_RECIP_UU_BIT1 (PTR(a)[0], PTR(b)[0]); - } + { + TRACE (printf ("swap\n")); + mpz_swap (a, b); + result_bit1 ^= JACOBI_RECIP_UU_BIT1 (PTR(a)[0], PTR(b)[0]); + } if (mpz_cmp_ui (b, 1) == 0) - break; + break; mpz_sub (a, a, b); TRACE (printf ("sub\n"); - mpz_trace (" a", a)); + mpz_trace (" a", a)); if (mpz_sgn (a) == 0) - goto zero; + goto zero; twos = mpz_scan1 (a, 0L); mpz_fdiv_q_2exp (a, a, twos); TRACE (printf ("twos %lu\n", twos); - mpz_trace (" a", a)); + mpz_trace (" a", a)); result_bit1 ^= JACOBI_TWOS_U_BIT1 (twos, PTR(b)[0]); } diff --git a/tests/spinner.c b/tests/spinner.c index a16c8e4eb..343ecb550 100644 --- a/tests/spinner.c +++ b/tests/spinner.c @@ -70,7 +70,7 @@ spinner_signal (int signum) This is done the first time spinner() is called, so an application doesn't need to call this directly. - + The spinner is only wanted if the output is a tty. */ #define SPINNER_WANTED_INIT() \ @@ -80,8 +80,8 @@ void spinner_init (void) { spinner_wanted = isatty (fileno (stdout)); - if (spinner_wanted == -1) - abort (); + if (spinner_wanted == -1) + abort (); if (!spinner_wanted) return; @@ -116,14 +116,14 @@ spinner (void) spinner_tick = 0; if (spinner_count != 0) - { - sprintf (buf+1, " %lu\r", spinner_count); - } + { + sprintf (buf+1, " %lu\r", spinner_count); + } else - { - buf[1] = '\r'; - buf[2] = '\0'; - } + { + buf[1] = '\r'; + buf[2] = '\0'; + } fputs (buf, stdout); } } diff --git a/tests/x86call.asm b/tests/x86call.asm index 407fc9550..47af42b72 100644 --- a/tests/x86call.asm +++ b/tests/x86call.asm @@ -1,19 +1,19 @@ dnl x86 calling conventions checking. dnl Copyright 2000, 2003 Free Software Foundation, Inc. -dnl +dnl dnl This file is part of the GNU MP Library. -dnl +dnl dnl The GNU MP Library is free software; you can redistribute it and/or dnl modify it under the terms of the GNU Lesser General Public License as dnl published by the Free Software Foundation; either version 3 of the dnl License, or (at your option) any later version. -dnl +dnl dnl The GNU MP Library is distributed in the hope that it will be useful, dnl but WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dnl Lesser General Public License for more details. -dnl +dnl dnl You should have received a copy of the GNU Lesser General Public License dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. diff --git a/tune/many.pl b/tune/many.pl index a8007fcb2..11b5cf452 100755 --- a/tune/many.pl +++ b/tune/many.pl @@ -294,7 +294,7 @@ my @table = 'speed' => 'SPEED_ROUTINE_MPN_BINARY_N', 'speed_flags'=> 'FLAG_R_OPTIONAL', }, - + { 'regexp'=> 'addmul_1|submul_1', 'ret' => 'mp_limb_t', @@ -529,7 +529,7 @@ my @table = 'ret' => 'mp_limb_t', 'args' => 'mp_srcptr cp', }, - + { 'regexp'=> 'jacobi', @@ -634,7 +634,7 @@ my @table = 'speed' => 'SPEED_ROUTINE_MPN_UNARY_2', 'speed_flags'=> 'FLAG_R', }, - + { 'regexp'=> 'mul_basecase', 'ret' => 'void', @@ -656,7 +656,7 @@ my @table = 'speed' => 'none', 'try-minsize' => 3, }, - + { 'regexp'=> 'popham', @@ -770,7 +770,7 @@ if (defined $ENV{table2}) { } -my %pictable = +my %pictable = ( 'yes' => { 'suffix' => '_pic', @@ -924,7 +924,7 @@ foreach my $file_full (@files) { elsif ($lang eq '.S') { @pic_choices=('no','yes'); } elsif ($lang eq '.h') { @pic_choices=('no'); } else { next }; - + my ($t, $file_match); foreach my $p (@table) { # print " ",$p->{'regexp'},"\n" if $opt{'t'}; @@ -961,7 +961,7 @@ foreach my $file_full (@files) { if (defined $t->{'carrys'}) { $carrys = $t->{'carrys'}; } else { $carrys = ['','c']; } print "carrys $carrys @$carrys\n" if $opt{'t'}; - + # some restriction functions are implemented, but they're not very useful my $restriction=''; @@ -982,9 +982,9 @@ foreach my $file_full (@files) { die "Can't determine suffix for: $file_full (path $path)\n"; } print "suffix $suffix\n" if $opt{'t'}; - + $count_files++; - + foreach my $obj (@{$objs}) { print "obj $obj\n" if $opt{'t'}; @@ -1005,7 +1005,7 @@ foreach my $file_full (@files) { foreach my $pic (map {$pictable{$_}} @pic_choices) { print "pic $pic->{'suffix'}\n" if $opt{'t'}; - + my $objbase = "${obj}_$suffix$pic->{'suffix'}"; print "objbase $objbase\n" if $opt{'t'}; @@ -1014,7 +1014,7 @@ foreach my $file_full (@files) { } my $tmp_file = "tmp-$objbase.c"; - + my $renaming; foreach my $fun (@{$funs}) { if ($mpX eq 'mpn_' && $lang eq '.c') { @@ -1143,14 +1143,14 @@ EOF if (! defined $args) { $args = $t->{'args'}; } if (! defined $args) { die "Need args for $fun\n"; } print "args $args\n" if $opt{'t'}; - + foreach my $carry (@$carrys) { print "carry $carry\n" if $opt{'t'}; my $fun_carry = $fun; if (! ($fun_carry =~ s/_1/_1$carry/)) { $fun_carry = "$fun$carry"; } print "fun_carry $fun_carry\n" if $opt{'t'}; - + if ($lang =~ /\.(asm|S)/ && ! grep(m"PROLOGUE\((.* )?$mpX$fun_carry[ ,)]",@file_contents)) { print "no PROLOGUE $mpX$fun_carry\n" if $opt{'t'}; @@ -1166,7 +1166,7 @@ EOF print "no mention of #define $fun_carry\n" if $opt{'t'}; next; } - + $count_functions++; my $carryarg; @@ -1174,7 +1174,7 @@ EOF if ($carry eq '') { $carryarg = ''; } else { $carryarg = ', mp_limb_t carry'; } print "carryarg $carryarg\n" if $opt{'t'}; - + my $funfull="$mpX${fun_carry}_$suffix$pic->{'suffix'}"; print "funfull $funfull\n" if $opt{'t'}; @@ -1183,7 +1183,7 @@ EOF $SPEED_EXTRA_PROTOS .= $proto; $TRY_EXTRA_PROTOS .= $proto; } - + my $try_type = $t->{"try-$fun"}; $try_type = $t->{'try'} if ! defined $try_type; if (! defined $try_type) { @@ -1194,7 +1194,7 @@ EOF } } print "try_type $try_type\n" if $opt{'t'}; - + my $try_minsize = $t->{'try-minsize'}; if (defined $try_minsize) { $try_minsize = ", " . $try_minsize; @@ -1202,7 +1202,7 @@ EOF $try_minsize = ""; } print "try_minsize $try_minsize\n" if $opt{'t'}; - + if ($try_type ne 'none') { $TRY_EXTRA_ROUTINES .= " { TRY($mpX${fun_carry}_$suffix$pic->{'suffix'}), $try_type$try_minsize }, \\\n"; @@ -1211,7 +1211,7 @@ EOF my $speed_flags = $t->{'speed_flags'}; $speed_flags = '0' if ! defined $speed_flags; print "speed_flags $speed_flags\n" if $opt{'t'}; - + my $speed_routine = $t->{'speed'}; $speed_routine = "SPEED_ROUTINE_\U$mpX\U$fun" if !defined $speed_routine; @@ -1219,19 +1219,19 @@ EOF $speed_routine = "$speed_routine\U$carry"; } print "speed_routine $speed_routine\n" if $opt{'t'}; - + my @speed_suffixes = (); push (@speed_suffixes, '') if $speed_routine ne 'none'; push (@speed_suffixes, @{$t->{'speed_suffixes'}}) if defined $t->{'speed_suffixes'}; - + my $macro_speed = $t->{'macro-speed'}; $macro_speed = "$speed_routine ($fun_carry)" if ! defined $macro_speed; $macro_speed =~ s/\$fun/$fun_carry/g; foreach my $S (@speed_suffixes) { my $Sfunfull="$mpX${fun_carry}${S}_$suffix$pic->{'suffix'}"; - + $SPEED_EXTRA_PROTOS .= "double speed_$Sfunfull _PROTO ((struct speed_params *s)); \\\n"; $SPEED_EXTRA_ROUTINES .= @@ -1323,7 +1323,7 @@ EOF close MAKEFILE or die; -print "Total $count_files files, $count_functions functions\n"; +print "Total $count_files files, $count_functions functions\n"; diff --git a/tune/noop.c b/tune/noop.c index f5e756dc8..7c7f1b5fe 100644 --- a/tune/noop.c +++ b/tune/noop.c @@ -51,7 +51,7 @@ noop_wxys (mp_ptr wp, mp_srcptr xp, mp_srcptr yp, mp_size_t size) } /*ARGSUSED*/ -void +void mpn_cache_fill_dummy (mp_limb_t n) { } diff --git a/tune/time.c b/tune/time.c index 6187c13f8..e52b62a90 100644 --- a/tune/time.c +++ b/tune/time.c @@ -276,11 +276,11 @@ static const int have_mftb = 1; unsigned __h1, __l, __h2; \ do { \ asm volatile ("mftbu %0\n" \ - "mftb %1\n" \ - "mftbu %2" \ - : "=r" (__h1), \ - "=r" (__l), \ - "=r" (__h2)); \ + "mftb %1\n" \ + "mftbu %2" \ + : "=r" (__h1), \ + "=r" (__l), \ + "=r" (__h2)); \ } while (__h1 != __h2); \ a[0] = __l; \ a[1] = __h1; \ @@ -411,7 +411,7 @@ char * unittime_string (double t) { static char buf[128]; - + const char *unit; int prec; @@ -464,16 +464,16 @@ cycles_works_p (void) old_handler = signal (SIGILL, cycles_works_handler); if (old_handler == SIG_ERR) { - if (speed_option_verbose) - printf ("cycles_works_p(): SIGILL not supported, assuming speed_cyclecounter() works\n"); - goto yes; + if (speed_option_verbose) + printf ("cycles_works_p(): SIGILL not supported, assuming speed_cyclecounter() works\n"); + goto yes; } if (setjmp (cycles_works_buf)) { - if (speed_option_verbose) - printf ("cycles_works_p(): SIGILL during speed_cyclecounter(), so doesn't work\n"); - result = 0; - goto done; + if (speed_option_verbose) + printf ("cycles_works_p(): SIGILL during speed_cyclecounter(), so doesn't work\n"); + result = 0; + goto done; } speed_cyclecounter (cycles); signal (SIGILL, old_handler); @@ -509,12 +509,12 @@ clk_tck (void) if (result != -1L) { if (speed_option_verbose) - printf ("sysconf(_SC_CLK_TCK) is %ld per second\n", result); + printf ("sysconf(_SC_CLK_TCK) is %ld per second\n", result); return result; } fprintf (stderr, - "sysconf(_SC_CLK_TCK) not working, using CLK_TCK instead\n"); + "sysconf(_SC_CLK_TCK) not working, using CLK_TCK instead\n"); #endif #ifdef CLK_TCK @@ -560,52 +560,52 @@ clk_tck (void) type st, et; \ long dt, half_tick; \ unsigned attempt, reps, i, j; \ - \ + \ if (result != -1) \ return result; \ - \ + \ result = 0; \ half_tick = (1000000L / clk_tck ()) / 2; \ - \ + \ for (attempt = 0; attempt < 5; attempt++) \ { \ - reps = 0; \ - for (;;) \ - { \ - get (st); \ - for (i = 0; i < reps; i++) \ - for (j = 0; j < 100; j++) \ - noop_1 (CNST_LIMB(0)); \ - get (et); \ - \ - dt = (sec(et)-sec(st))*1000000L + usec(et)-usec(st); \ - \ - if (speed_option_verbose >= 2) \ - printf ("%s attempt=%u, reps=%u, dt=%ld\n", \ - name, attempt, reps, dt); \ - \ - if (dt >= 2) \ - break; \ - \ - reps = (reps == 0 ? 1 : 2*reps); \ - if (reps == 0) \ - break; /* uint overflow, not normal */ \ - } \ - \ - if (dt < half_tick) \ - { \ - result = 1; \ - break; \ - } \ + reps = 0; \ + for (;;) \ + { \ + get (st); \ + for (i = 0; i < reps; i++) \ + for (j = 0; j < 100; j++) \ + noop_1 (CNST_LIMB(0)); \ + get (et); \ + \ + dt = (sec(et)-sec(st))*1000000L + usec(et)-usec(st); \ + \ + if (speed_option_verbose >= 2) \ + printf ("%s attempt=%u, reps=%u, dt=%ld\n", \ + name, attempt, reps, dt); \ + \ + if (dt >= 2) \ + break; \ + \ + reps = (reps == 0 ? 1 : 2*reps); \ + if (reps == 0) \ + break; /* uint overflow, not normal */ \ + } \ + \ + if (dt < half_tick) \ + { \ + result = 1; \ + break; \ + } \ } \ - \ + \ if (speed_option_verbose) \ { \ - if (result) \ - printf ("%s is microsecond accurate\n", name); \ - else \ - printf ("%s is only %s clock tick accurate\n", \ - name, unittime_string (1.0/clk_tck())); \ + if (result) \ + printf ("%s is microsecond accurate\n", name); \ + else \ + printf ("%s is only %s clock tick accurate\n", \ + name, unittime_string (1.0/clk_tck())); \ } \ return result; \ } @@ -618,7 +618,7 @@ gettimeofday_microseconds_p (void) #define timeval_tv_sec(t) ((t).tv_sec) #define timeval_tv_usec(t) ((t).tv_usec) MICROSECONDS_P ("gettimeofday", struct_timeval, - call_gettimeofday, timeval_tv_sec, timeval_tv_usec); + call_gettimeofday, timeval_tv_sec, timeval_tv_usec); } int @@ -628,7 +628,7 @@ getrusage_microseconds_p (void) #define rusage_tv_sec(t) ((t).ru_utime.tv_sec) #define rusage_tv_usec(t) ((t).ru_utime.tv_usec) MICROSECONDS_P ("getrusage", struct_rusage, - call_getrusage, rusage_tv_sec, rusage_tv_usec); + call_getrusage, rusage_tv_sec, rusage_tv_usec); } /* Test whether getrusage goes backwards, return non-zero if it does @@ -665,25 +665,25 @@ getrusage_backwards_p (void) getrusage (0, &next); if (next.ru_utime.tv_sec < prev.ru_utime.tv_sec - || (next.ru_utime.tv_sec == prev.ru_utime.tv_sec - && next.ru_utime.tv_usec < prev.ru_utime.tv_usec)) - { - if (speed_option_verbose) - printf ("getrusage went backwards (attempt %d: %ld.%06ld -> %ld.%06ld)\n", - i, - prev.ru_utime.tv_sec, prev.ru_utime.tv_usec, - next.ru_utime.tv_sec, next.ru_utime.tv_usec); - result = 1; - break; - } + || (next.ru_utime.tv_sec == prev.ru_utime.tv_sec + && next.ru_utime.tv_usec < prev.ru_utime.tv_usec)) + { + if (speed_option_verbose) + printf ("getrusage went backwards (attempt %d: %ld.%06ld -> %ld.%06ld)\n", + i, + prev.ru_utime.tv_sec, prev.ru_utime.tv_usec, + next.ru_utime.tv_sec, next.ru_utime.tv_usec); + result = 1; + break; + } /* minimum 1000 attempts, then stop after either 0.1 seconds or 50000 - attempts, whichever comes first */ + attempts, whichever comes first */ d = 1000000 * (next.ru_utime.tv_sec - start.ru_utime.tv_sec) - + (next.ru_utime.tv_usec - start.ru_utime.tv_usec); + + (next.ru_utime.tv_usec - start.ru_utime.tv_usec); i++; if (i > 50000 || (i > 1000 && d > 100000)) - break; + break; } return result; @@ -721,7 +721,7 @@ cgt_works_p (void) if (! have_cgt_id) { if (speed_option_verbose) - printf ("clock_gettime don't know what ID to use\n"); + printf ("clock_gettime don't know what ID to use\n"); result = 0; return result; } @@ -733,7 +733,7 @@ cgt_works_p (void) if (clock_gettime (CGT_ID, &unit) != 0) { if (speed_option_verbose) - printf ("clock_gettime id=%d error: %s\n", CGT_ID, strerror (errno)); + printf ("clock_gettime id=%d error: %s\n", CGT_ID, strerror (errno)); result = 0; return result; } @@ -742,14 +742,14 @@ cgt_works_p (void) if (clock_getres (CGT_ID, &unit) != 0) { if (speed_option_verbose) - printf ("clock_getres id=%d error: %s\n", CGT_ID, strerror (errno)); + printf ("clock_getres id=%d error: %s\n", CGT_ID, strerror (errno)); result = 0; return result; } cgt_unittime = unit.tv_sec + unit.tv_nsec * 1e-9; printf ("clock_gettime is %s accurate\n", - unittime_string (cgt_unittime)); + unittime_string (cgt_unittime)); result = 1; return result; } @@ -762,8 +762,8 @@ freq_measure_mftb_one (void) #define timeval_tv_sec(t) ((t).tv_sec) #define timeval_tv_usec(t) ((t).tv_usec) FREQ_MEASURE_ONE ("mftb", struct_timeval, - call_gettimeofday, MFTB, - timeval_tv_sec, timeval_tv_usec); + call_gettimeofday, MFTB, + timeval_tv_sec, timeval_tv_usec); } @@ -793,13 +793,13 @@ mftb_works_p (void) if (old_handler == SIG_ERR) { if (speed_option_verbose) - printf ("mftb_works_p(): SIGILL not supported, assuming mftb works\n"); + printf ("mftb_works_p(): SIGILL not supported, assuming mftb works\n"); return 1; } if (setjmp (mftb_works_buf)) { if (speed_option_verbose) - printf ("mftb_works_p(): SIGILL during mftb, so doesn't work\n"); + printf ("mftb_works_p(): SIGILL during mftb, so doesn't work\n"); return 0; } MFTB (a); @@ -824,7 +824,7 @@ mftb_works_p (void) if (cycletime == -1.0) { if (speed_option_verbose) - printf ("mftb_works_p(): cannot measure mftb period\n"); + printf ("mftb_works_p(): cannot measure mftb period\n"); return 0; } @@ -855,7 +855,7 @@ sgi_works_p (void) { /* ENODEV is the error when a counter is not available */ if (speed_option_verbose) - printf ("syssgi SGI_QUERY_CYCLECNTR error: %s\n", strerror (errno)); + printf ("syssgi SGI_QUERY_CYCLECNTR error: %s\n", strerror (errno)); result = 0; return result; } @@ -869,10 +869,10 @@ sgi_works_p (void) if (size == -1) { if (speed_option_verbose) - { - printf ("syssgi SGI_CYCLECNTR_SIZE error: %s\n", strerror (errno)); - printf (" will assume size==4\n"); - } + { + printf ("syssgi SGI_CYCLECNTR_SIZE error: %s\n", strerror (errno)); + printf (" will assume size==4\n"); + } size = 32; } #else @@ -897,7 +897,7 @@ sgi_works_p (void) if (fd == -1) { if (speed_option_verbose) - printf ("open /dev/mmem: %s\n", strerror (errno)); + printf ("open /dev/mmem: %s\n", strerror (errno)); result = 0; return result; } @@ -906,14 +906,14 @@ sgi_works_p (void) if (virtpage == (void *) -1) { if (speed_option_verbose) - printf ("mmap /dev/mmem: %s\n", strerror (errno)); + printf ("mmap /dev/mmem: %s\n", strerror (errno)); result = 0; return result; } /* address of least significant 4 bytes, knowing mips is big endian */ sgi_addr = (unsigned *) ((char *) virtpage + offset - + size/8 - sizeof(unsigned)); + + size/8 - sizeof(unsigned)); result = 1; return result; @@ -951,72 +951,72 @@ speed_time_init (void) /* only used if a supplementary method is chosen below */ cycles_limit = (have_cycles == 1 ? M_2POW32 : M_2POW64) / 2.0 - * speed_cycletime; + * speed_cycletime; if (have_grus && getrusage_microseconds_p() && ! getrusage_backwards_p()) - { - /* this is a good combination */ - use_grus = 1; - supplement_unittime = grus_unittime = 1.0e-6; - strcpy (speed_time_string, "CPU cycle counter, supplemented by microsecond getrusage()"); - } + { + /* this is a good combination */ + use_grus = 1; + supplement_unittime = grus_unittime = 1.0e-6; + strcpy (speed_time_string, "CPU cycle counter, supplemented by microsecond getrusage()"); + } else if (have_cycles == 1) - { - /* When speed_cyclecounter has a limited range, look for something - to supplement it. */ - if (have_gtod && gettimeofday_microseconds_p()) - { - use_gtod = 1; - supplement_unittime = gtod_unittime = 1.0e-6; - strcpy (speed_time_string, "CPU cycle counter, supplemented by microsecond gettimeofday()"); - } - else if (have_grus) - { - use_grus = 1; - supplement_unittime = grus_unittime = 1.0 / (double) clk_tck (); - sprintf (speed_time_string, "CPU cycle counter, supplemented by %s clock tick getrusage()", unittime_string (supplement_unittime)); - } - else if (have_times) - { - use_times = 1; - supplement_unittime = times_unittime = 1.0 / (double) clk_tck (); - sprintf (speed_time_string, "CPU cycle counter, supplemented by %s clock tick times()", unittime_string (supplement_unittime)); - } - else if (have_gtod) - { - use_gtod = 1; - supplement_unittime = gtod_unittime = 1.0 / (double) clk_tck (); - sprintf (speed_time_string, "CPU cycle counter, supplemented by %s clock tick gettimeofday()", unittime_string (supplement_unittime)); - } - else - { - fprintf (stderr, "WARNING: cycle counter is 32 bits and there's no other functions.\n"); - fprintf (stderr, " Wraparounds may produce bad results on long measurements.\n"); - } - } + { + /* When speed_cyclecounter has a limited range, look for something + to supplement it. */ + if (have_gtod && gettimeofday_microseconds_p()) + { + use_gtod = 1; + supplement_unittime = gtod_unittime = 1.0e-6; + strcpy (speed_time_string, "CPU cycle counter, supplemented by microsecond gettimeofday()"); + } + else if (have_grus) + { + use_grus = 1; + supplement_unittime = grus_unittime = 1.0 / (double) clk_tck (); + sprintf (speed_time_string, "CPU cycle counter, supplemented by %s clock tick getrusage()", unittime_string (supplement_unittime)); + } + else if (have_times) + { + use_times = 1; + supplement_unittime = times_unittime = 1.0 / (double) clk_tck (); + sprintf (speed_time_string, "CPU cycle counter, supplemented by %s clock tick times()", unittime_string (supplement_unittime)); + } + else if (have_gtod) + { + use_gtod = 1; + supplement_unittime = gtod_unittime = 1.0 / (double) clk_tck (); + sprintf (speed_time_string, "CPU cycle counter, supplemented by %s clock tick gettimeofday()", unittime_string (supplement_unittime)); + } + else + { + fprintf (stderr, "WARNING: cycle counter is 32 bits and there's no other functions.\n"); + fprintf (stderr, " Wraparounds may produce bad results on long measurements.\n"); + } + } if (use_grus || use_times || use_gtod) - { - /* must know cycle period to compare cycles to other measuring - (via cycles_limit) */ - speed_cycletime_need_seconds (); - - if (speed_precision * supplement_unittime > cycles_limit) - { - fprintf (stderr, "WARNING: requested precision can't always be achieved due to limited range\n"); - fprintf (stderr, " cycle counter and limited precision supplemental method\n"); - fprintf (stderr, " (%s)\n", speed_time_string); - } - } + { + /* must know cycle period to compare cycles to other measuring + (via cycles_limit) */ + speed_cycletime_need_seconds (); + + if (speed_precision * supplement_unittime > cycles_limit) + { + fprintf (stderr, "WARNING: requested precision can't always be achieved due to limited range\n"); + fprintf (stderr, " cycle counter and limited precision supplemental method\n"); + fprintf (stderr, " (%s)\n", speed_time_string); + } + } } else if (have_stck) { strcpy (speed_time_string, "STCK timestamp"); /* stck is in units of 2^-12 microseconds, which is very likely higher - resolution than a cpu cycle */ + resolution than a cpu cycle */ if (speed_cycletime == 0.0) - speed_cycletime_fail - ("Need to know CPU frequency for effective stck unit"); + speed_cycletime_fail + ("Need to know CPU frequency for effective stck unit"); speed_unittime = MAX (speed_cycletime, STCK_PERIOD); DEFAULT (speed_precision, 10000); } @@ -1026,7 +1026,7 @@ speed_time_init (void) DEFAULT (speed_precision, 10000); speed_unittime = mftb_unittime; sprintf (speed_time_string, "mftb counter (%s)", - unittime_string (speed_unittime)); + unittime_string (speed_unittime)); } else if (have_sgi && sgi_works_p ()) { @@ -1034,7 +1034,7 @@ speed_time_init (void) DEFAULT (speed_precision, 10000); speed_unittime = sgi_unittime; sprintf (speed_time_string, "syssgi() mmap counter (%s), supplemented by millisecond getrusage()", - unittime_string (speed_unittime)); + unittime_string (speed_unittime)); /* supplemented with getrusage, which we assume to have 1ms resolution */ use_grus = 1; supplement_unittime = 1e-3; @@ -1047,22 +1047,22 @@ speed_time_init (void) read_real_time (&t, sizeof(t)); switch (t.flag) { case RTC_POWER: - /* FIXME: What's the actual RTC resolution? */ - speed_unittime = 1e-7; - strcpy (speed_time_string, "read_real_time() power nanoseconds"); - break; + /* FIXME: What's the actual RTC resolution? */ + speed_unittime = 1e-7; + strcpy (speed_time_string, "read_real_time() power nanoseconds"); + break; case RTC_POWER_PC: - t.tb_high = 1; - t.tb_low = 0; - time_base_to_time (&t, sizeof(t)); - speed_unittime = TIMEBASESTRUCT_SECS(&t) / M_2POW32; - sprintf (speed_time_string, "%s read_real_time() powerpc ticks", - unittime_string (speed_unittime)); - break; + t.tb_high = 1; + t.tb_low = 0; + time_base_to_time (&t, sizeof(t)); + speed_unittime = TIMEBASESTRUCT_SECS(&t) / M_2POW32; + sprintf (speed_time_string, "%s read_real_time() powerpc ticks", + unittime_string (speed_unittime)); + break; default: - fprintf (stderr, "ERROR: Unrecognised timebasestruct_t flag=%d\n", - t.flag); - abort (); + fprintf (stderr, "ERROR: Unrecognised timebasestruct_t flag=%d\n", + t.flag); + abort (); } } else if (have_cgt && cgt_works_p() && cgt_unittime < 1.5e-6) @@ -1077,7 +1077,7 @@ speed_time_init (void) else if (have_times && clk_tck() > 1000000) { /* Cray vector systems have times() which is clock cycle resolution - (eg. 450 MHz). */ + (eg. 450 MHz). */ DEFAULT (speed_precision, 10000); goto choose_times; } @@ -1108,7 +1108,7 @@ speed_time_init (void) use_times = 1; speed_unittime = times_unittime = 1.0 / (double) clk_tck (); sprintf (speed_time_string, "%s clock tick times()", - unittime_string (speed_unittime)); + unittime_string (speed_unittime)); } else if (have_grus) { @@ -1117,7 +1117,7 @@ speed_time_init (void) speed_unittime = grus_unittime = 1.0 / (double) clk_tck (); DEFAULT (speed_precision, 200); sprintf (speed_time_string, "%s clock tick getrusage()\n", - unittime_string (speed_unittime)); + unittime_string (speed_unittime)); } else if (have_gtod) { @@ -1126,7 +1126,7 @@ speed_time_init (void) speed_unittime = gtod_unittime = 1.0 / (double) clk_tck (); DEFAULT (speed_precision, 200); sprintf (speed_time_string, "%s clock tick gettimeofday()", - unittime_string (speed_unittime)); + unittime_string (speed_unittime)); } else { @@ -1141,10 +1141,10 @@ speed_time_init (void) printf (" speed_precision %d\n", speed_precision); printf (" speed_unittime %.2g\n", speed_unittime); if (supplement_unittime) - printf (" supplement_unittime %.2g\n", supplement_unittime); + printf (" supplement_unittime %.2g\n", supplement_unittime); printf (" use_tick_boundary %d\n", use_tick_boundary); if (have_cycles) - printf (" cycles_limit %.2g seconds\n", cycles_limit); + printf (" cycles_limit %.2g seconds\n", cycles_limit); } } @@ -1194,25 +1194,25 @@ speed_starttime (void) if (have_grus && use_grus) { if (use_tick_boundary) - grus_tick_boundary (); + grus_tick_boundary (); else - getrusage (0, &start_grus); + getrusage (0, &start_grus); } if (have_gtod && use_gtod) { if (use_tick_boundary) - gtod_tick_boundary (); + gtod_tick_boundary (); else - gettimeofday (&start_gtod, NULL); + gettimeofday (&start_gtod, NULL); } if (have_times && use_times) { if (use_tick_boundary) - times_tick_boundary (); + times_tick_boundary (); else - times (&start_times); + times (&start_times); } if (have_cgt && use_cgt) @@ -1321,7 +1321,7 @@ timespec_diff_secs (const struct_timespec *end, const struct_timespec *start) /* This is for use after time_base_to_time, ie. for seconds and nanoseconds. */ double timebasestruct_diff_secs (const timebasestruct_t *end, - const timebasestruct_t *start) + const timebasestruct_t *start) { DIFF_SECS_ROUTINE (tb_high, tb_low, 1e-9); } @@ -1350,7 +1350,7 @@ speed_endtime (void) do { \ if (speed_option_verbose >= 3) \ printf ("speed_endtime(): cycle counter limit exceeded, used %s\n", \ - name); \ + name); \ result = value; \ goto done; \ } while (0) @@ -1387,44 +1387,44 @@ speed_endtime (void) { printf ("speed_endtime():\n"); if (use_cycles) - printf (" cycles 0x%X,0x%X -> 0x%X,0x%X\n", - start_cycles[1], start_cycles[0], - end_cycles[1], end_cycles[0]); + printf (" cycles 0x%X,0x%X -> 0x%X,0x%X\n", + start_cycles[1], start_cycles[0], + end_cycles[1], end_cycles[0]); if (use_stck) - printf (" stck 0x%lX -> 0x%lX\n", start_stck, end_stck); + printf (" stck 0x%lX -> 0x%lX\n", start_stck, end_stck); if (use_mftb) - printf (" mftb 0x%X,%08X -> 0x%X,%08X\n", - start_mftb[1], start_mftb[0], - end_mftb[1], end_mftb[0]); + printf (" mftb 0x%X,%08X -> 0x%X,%08X\n", + start_mftb[1], start_mftb[0], + end_mftb[1], end_mftb[0]); if (use_sgi) - printf (" sgi 0x%X -> 0x%X\n", start_sgi, end_sgi); + printf (" sgi 0x%X -> 0x%X\n", start_sgi, end_sgi); if (use_rrt) - printf (" read_real_time (%d)%u,%u -> (%d)%u,%u\n", - start_rrt.flag, start_rrt.tb_high, start_rrt.tb_low, - end_rrt.flag, end_rrt.tb_high, end_rrt.tb_low); + printf (" read_real_time (%d)%u,%u -> (%d)%u,%u\n", + start_rrt.flag, start_rrt.tb_high, start_rrt.tb_low, + end_rrt.flag, end_rrt.tb_high, end_rrt.tb_low); if (use_cgt) - printf (" clock_gettime %ld.%09ld -> %ld.%09ld\n", - start_cgt.tv_sec, start_cgt.tv_nsec, - end_cgt.tv_sec, end_cgt.tv_nsec); + printf (" clock_gettime %ld.%09ld -> %ld.%09ld\n", + start_cgt.tv_sec, start_cgt.tv_nsec, + end_cgt.tv_sec, end_cgt.tv_nsec); if (use_gtod) - printf (" gettimeofday %ld.%06ld -> %ld.%06ld\n", - start_gtod.tv_sec, start_gtod.tv_usec, - end_gtod.tv_sec, end_gtod.tv_usec); + printf (" gettimeofday %ld.%06ld -> %ld.%06ld\n", + start_gtod.tv_sec, start_gtod.tv_usec, + end_gtod.tv_sec, end_gtod.tv_usec); if (use_grus) - printf (" getrusage %ld.%06ld -> %ld.%06ld\n", - start_grus.ru_utime.tv_sec, start_grus.ru_utime.tv_usec, - end_grus.ru_utime.tv_sec, end_grus.ru_utime.tv_usec); + printf (" getrusage %ld.%06ld -> %ld.%06ld\n", + start_grus.ru_utime.tv_sec, start_grus.ru_utime.tv_usec, + end_grus.ru_utime.tv_sec, end_grus.ru_utime.tv_usec); if (use_times) - printf (" times %ld -> %ld\n", - start_times.tms_utime, end_times.tms_utime); + printf (" times %ld -> %ld\n", + start_times.tms_utime, end_times.tms_utime); } if (use_rrt) @@ -1446,14 +1446,14 @@ speed_endtime (void) t_grus = rusage_diff_secs (&end_grus, &start_grus); /* Use getrusage() if the cycle counter limit would be exceeded, or if - it provides enough accuracy already. */ - if (use_cycles) - { - if (t_grus >= speed_precision*grus_unittime) - END_ENOUGH ("getrusage()", t_grus); - if (t_grus >= cycles_limit) - END_EXCEED ("getrusage()", t_grus); - } + it provides enough accuracy already. */ + if (use_cycles) + { + if (t_grus >= speed_precision*grus_unittime) + END_ENOUGH ("getrusage()", t_grus); + if (t_grus >= cycles_limit) + END_EXCEED ("getrusage()", t_grus); + } } if (use_times) @@ -1461,14 +1461,14 @@ speed_endtime (void) t_times = (end_times.tms_utime - start_times.tms_utime) * times_unittime; /* Use times() if the cycle counter limit would be exceeded, or if - it provides enough accuracy already. */ - if (use_cycles) - { - if (t_times >= speed_precision*times_unittime) - END_ENOUGH ("times()", t_times); - if (t_times >= cycles_limit) - END_EXCEED ("times()", t_times); - } + it provides enough accuracy already. */ + if (use_cycles) + { + if (t_times >= speed_precision*times_unittime) + END_ENOUGH ("times()", t_times); + if (t_times >= cycles_limit) + END_EXCEED ("times()", t_times); + } } if (use_gtod) @@ -1476,21 +1476,21 @@ speed_endtime (void) t_gtod = timeval_diff_secs (&end_gtod, &start_gtod); /* Use gettimeofday() if it measured a value bigger than the cycle - counter can handle. */ - if (use_cycles) - { - if (t_gtod >= cycles_limit) - END_EXCEED ("gettimeofday()", t_gtod); - } + counter can handle. */ + if (use_cycles) + { + if (t_gtod >= cycles_limit) + END_EXCEED ("gettimeofday()", t_gtod); + } } - + if (use_mftb) { t_mftb = speed_mftb_diff (end_mftb, start_mftb) * mftb_unittime; END_USE ("mftb", t_mftb); } - if (use_stck) + if (use_stck) { t_stck = (end_stck - start_stck) * STCK_PERIOD; END_USE ("stck", t_stck); @@ -1502,10 +1502,10 @@ speed_endtime (void) END_USE ("SGI hardware counter", t_sgi); } - if (use_cycles) + if (use_cycles) { t_cycles = speed_cyclecounter_diff (end_cycles, start_cycles) - * speed_cycletime; + * speed_cycletime; END_USE ("cycle counter", t_cycles); } @@ -1526,7 +1526,7 @@ speed_endtime (void) if (result < 0.0) { if (speed_option_verbose >= 2) - fprintf (stderr, "speed_endtime(): warning, treating negative time as zero: %.9f\n", result); + fprintf (stderr, "speed_endtime(): warning, treating negative time as zero: %.9f\n", result); result = 0.0; } return result; |