From 3936fe2a01920fe1fb3d7bf34ade29da706ff55e Mon Sep 17 00:00:00 2001 From: imp Date: Wed, 6 Jan 1999 19:46:56 +0000 Subject: Fix printf errors in the hflag case. Fix old bug with bogus casing to (long). Document the true limits of factor on 64-bit architectures. Submitted by: bde --- games/factor/factor.6 | 12 ++++++------ games/factor/factor.c | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'games/factor') diff --git a/games/factor/factor.6 b/games/factor/factor.6 index 4844780..316abdd 100644 --- a/games/factor/factor.6 +++ b/games/factor/factor.6 @@ -52,12 +52,12 @@ factor, primes \- factor a number, generate primes .SH DESCRIPTION The .I factor -utility will factor integers between 0 and 4294967295 inclusive. -When a number is factored, it is printed, followed by a ``:'', -and the list of factors on a single line. -Factors are listed in ascending order, and are preceded by a space. -If a factor divides a value more than once, it will be printed -more than once. +utility will factor integers between 0 and ULONG_MAX (4294967295 on 32 +bit architectures, 18446744073709551615 on 64 bit ones), inclusive. +When a number is factored, it is printed, followed by a ``:'', and the +list of factors on a single line. Factors are listed in ascending +order, and are preceded by a space. If a factor divides a value more +than once, it will be printed more than once. .PP When .I factor diff --git a/games/factor/factor.c b/games/factor/factor.c index c5fdbaa..aa64dd5 100644 --- a/games/factor/factor.c +++ b/games/factor/factor.c @@ -173,7 +173,7 @@ pr_fact(val) } /* Factor value. */ - (void)printf(hflag ? "0x%x:" : "%lu:", val); + (void)printf(hflag ? "0x%lx:" : "%lu:", val); for (fact = &prime[0]; val > 1; ++fact) { /* Look for the smallest factor. */ do { @@ -183,15 +183,15 @@ pr_fact(val) /* Watch for primes larger than the table. */ if (fact > pr_limit) { - (void)printf(hflag ? " 0x%x" : " %lu", val); + (void)printf(hflag ? " 0x%lx" : " %lu", val); break; } /* Divide factor out until none are left. */ do { - (void)printf(hflag ? " 0x%x" : " %lu", *fact); - val /= (long)*fact; - } while ((val % (long)*fact) == 0); + (void)printf(hflag ? " 0x%lx" : " %lu", *fact); + val /= *fact; + } while ((val % *fact) == 0); /* Let the user know we're doing something. */ (void)fflush(stdout); -- cgit v1.1