Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/factor Follow the Fundamental Theory of Algebra. Disal...



details:   https://anonhg.NetBSD.org/src/rev/ad57a484c942
branches:  trunk
changeset: 754915:ad57a484c942
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sat May 15 21:22:39 2010 +0000

description:
Follow the Fundamental Theory of Algebra. Disallow factorising of
numbers less than 2 as it is not
- naturally unique (negative numbers)
- finite (0)
- non-empty (1)

Discussed with the kristaps and wiz

diffstat:

 games/factor/factor.6 |  10 +++++-----
 games/factor/factor.c |  14 +++++---------
 2 files changed, 10 insertions(+), 14 deletions(-)

diffs (80 lines):

diff -r 035009b457a2 -r ad57a484c942 games/factor/factor.6
--- a/games/factor/factor.6     Sat May 15 20:47:23 2010 +0000
+++ b/games/factor/factor.6     Sat May 15 21:22:39 2010 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: factor.6,v 1.11 2010/04/22 06:57:13 wiz Exp $
+.\"    $NetBSD: factor.6,v 1.12 2010/05/15 21:22:39 joerg Exp $
 .\"
 .\" Copyright (c) 1989, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -37,7 +37,7 @@
 .\"
 .\"   chongo <for a good prime call: 391581 * 2^216193 - 1> /\oo/\
 .\"
-.Dd April 22, 2010
+.Dd May 15, 2010
 .Dt FACTOR 6
 .Os
 .Sh NAME
@@ -49,7 +49,7 @@
 .Sh DESCRIPTION
 The
 .Nm
-utility factors positive integers.
+utility factors integers larger than 1.
 When a number is factored, it is printed, followed by a
 .Dq \&: ,
 and the list of
@@ -68,8 +68,8 @@
 .Nm
 reads numbers, one per line, from standard input, until end of file or error.
 Leading white-space and empty lines are ignored.
-Numbers may be preceded by a single \- or +, although negative numbers
-are rejected.
+Numbers may be preceded by a single +.
+Integer less than 2 are rejected.
 Numbers are terminated by a non-digit character (such as a newline).
 After a number is read, it is factored.
 Input lines must not be longer than
diff -r 035009b457a2 -r ad57a484c942 games/factor/factor.c
--- a/games/factor/factor.c     Sat May 15 20:47:23 2010 +0000
+++ b/games/factor/factor.c     Sat May 15 21:22:39 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: factor.c,v 1.23 2010/05/13 17:52:11 tnozaki Exp $      */
+/*     $NetBSD: factor.c,v 1.24 2010/05/15 21:22:39 joerg Exp $        */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)factor.c   8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: factor.c,v 1.23 2010/05/13 17:52:11 tnozaki Exp $");
+__RCSID("$NetBSD: factor.c,v 1.24 2010/05/15 21:22:39 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -177,7 +177,7 @@
        else
                for (; *argv != NULL; ++argv) {
                        if (argv[0][0] == '-')
-                               errx(1, "negative numbers aren't permitted.");
+                               errx(1, "numbers <= 1 aren't permitted.");
                        if (BN_dec2bn(&val, argv[0]) == 0)
                                errx(1, "%s: illegal numeric format.", argv[0]);
                        pr_fact(val);
@@ -204,12 +204,8 @@
        const ubig *fact;               /* The factor found. */
 
        /* Firewall - catch 0 and 1. */
-       if (BN_is_zero(val))    /* Historical practice; 0 just exits. */
-               exit(0);
-       if (BN_is_one(val)) {
-               printf("1: 1\n");
-               return;
-       }
+       if (BN_is_zero(val) || BN_is_one(val))
+               errx(1, "numbers <= 1 aren't permitted.");
 
        /* Factor value. */
 



Home | Main Index | Thread Index | Old Index