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
This commit is contained in:
parent
0061cc0461
commit
63f8ec6b73
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=42357
@ -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
|
||||
|
@ -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);
|
||||
|
@ -261,7 +261,7 @@ primes(start, stop)
|
||||
for (p = &prime[0], factor = prime[0];
|
||||
factor < stop && p <= pr_limit; factor = *(++p)) {
|
||||
if (factor >= start) {
|
||||
printf(hflag ? "0x%x\n" : "%lu\n", factor);
|
||||
printf(hflag ? "0x%lx\n" : "%lu\n", factor);
|
||||
}
|
||||
}
|
||||
/* return early if we are done */
|
||||
@ -324,7 +324,7 @@ primes(start, stop)
|
||||
*/
|
||||
for (q = table; q < tab_lim; ++q, start+=2) {
|
||||
if (*q) {
|
||||
printf(hflag ? "0x%x\n" : "%lu\n", start);
|
||||
printf(hflag ? "0x%lx\n" : "%lu\n", start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user