[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
factor [Was: coreutils v5.2.1 - stat.c]
From: |
Eric Blake |
Subject: |
factor [Was: coreutils v5.2.1 - stat.c] |
Date: |
Fri, 30 Sep 2005 22:35:05 +0000 |
> > + ['Ma', '-4294966201', {OUT => '-1 12197 352133'}],
>
> Now that I see these test cases I also see a reason why this is not a
> good idea. Currently, 'factor' outputs the unique factorization of
> the input number into primes. But there is no unique factorization
> for negative numbers. For example, OUT could have been '-12197
> 352133' or '12197 -352133'.
If we decide to permit negative numbers, it seems like '-1' as the
first factor would be the most useful, even though -1 is not a prime;
then all the remaining factors ARE positive primes. Then, for consistency,
-1 would print just -1, 0 would be an error, and 1 would print nothing.
But I can also see keeping the status quo of only accepting positive
integers, particularly since factor(1) is not standardized.
>
> I am becoming inclined to leave sleeping dogs lie here. Except
> perhaps 'factor' should also report an error if asked to factor zero.
Agreed, especially since zero is not a positive integer.
However, it would also be nice if factor continued on with its
remaining arguments, rather than exiting immediately on error:
Currently:
$ factor -- `seq -- -2 2`
stderr> factor: `-2' is not a valid positive integer
stderr> Try `./src/factor --help' for more information.
$ echo $?
1
Proposed (if we keep negatives illegal):
$ factor -- `seq -- -2 2`
stderr> factor: `-2' is not a valid positive integer
stderr> factor: `-1' is not a valid positive integer
stderr> factor: `0' is not a valid positive integer
stdout> 1:
stdout> 2: 2
$ echo $?
1
Proposed (if we decide to allow negatives):
$ factor -- `seq -- -2 2`
stdout> -2: -1 2
stdout> -1: -1
stderr> factor: `0' has no factors
stdout> 1:
stdout> 2: 2
$ echo $?
1
Also something to think about - if factor is changed to accept
negative numbers, then perhaps it should accept arguments
that look like options:
Current:
$ factor -2
stderr> factor: invalid option -- 2
stderr> Try `factor --help' for more information.
Proposed (if we keep negatives illegal):
$ factor -2
stderr> factor: `-2' is not a valid positive integer
stderr> Try `factor --help' for more information.
Proposed (if we decide to allow negatives):
$ factor -2
stdout> -2: -1 2
--
Eric Blake
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- factor [Was: coreutils v5.2.1 - stat.c],
Eric Blake <=