From owner-freebsd-bugs Mon Jan 27 20:40:21 2003 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 013A737B401 for ; Mon, 27 Jan 2003 20:40:18 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2C1AB43FA3 for ; Mon, 27 Jan 2003 20:40:08 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h0S4e7NS079512 for ; Mon, 27 Jan 2003 20:40:07 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h0S4e7kq079511; Mon, 27 Jan 2003 20:40:07 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D3C5F37B497 for ; Mon, 27 Jan 2003 20:35:34 -0800 (PST) Received: from jeff.tk (lsanca1-ar8-4-60-074-043.lsanca1.dsl-verizon.net [4.60.74.43]) by mx1.FreeBSD.org (Postfix) with SMTP id BB39243F3F for ; Mon, 27 Jan 2003 20:35:33 -0800 (PST) (envelope-from jeff@jeff.tk) Received: (qmail 28327 invoked by uid 1000); 28 Jan 2003 04:36:31 -0000 Message-Id: <20030128043631.28326.qmail@jeff.tk> Date: 28 Jan 2003 04:36:31 -0000 From: Jeff Connelly Reply-To: Jeff Connelly To: FreeBSD-gnats-submit@FreeBSD.org Cc: freebsd@xyzzy.cjb.net X-Send-Pr-Version: 3.113 Subject: misc/47576: [PATCH] factor(6)ing of negative numbers Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 47576 >Category: misc >Synopsis: [PATCH] factor(6)ing of negative numbers >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Jan 27 20:40:07 PST 2003 >Closed-Date: >Last-Modified: >Originator: Jeff Connelly >Release: FreeBSD 5.0-RELEASE i386 >Organization: >Environment: System: FreeBSD aptlap 5.0-RELEASE FreeBSD 5.0-RELEASE #5: Sun Jan 26 05:48:37 GMT 2003 root@aptlap:/usr/obj/usr/src/sys/APTLAP i386 >Description: factor(6) cannot factor negative numbers. >How-To-Repeat: # factor -- -4 >Fix: Patch given first factors -1 out of negatives, then factors the absolute value as usual. A patch has also been provided for the accompanying documentation. --- factor.c.patch begins here --- --- factor.c.orig Wed Oct 9 19:55:04 2002 +++ factor.c Mon Jan 27 07:29:30 2003 @@ -113,6 +113,7 @@ static BN_CTX *ctx; /* just use a global context */ static int hflag; +static int negflag; int main(int argc, char *argv[]) @@ -149,8 +150,7 @@ for (p = buf; isblank(*p); ++p); if (*p == '\n' || *p == '\0') continue; - if (*p == '-') - errx(1, "negative numbers aren't permitted."); + negflag = *p == '-'; if (BN_dec2bn(&val, buf) == 0 && BN_hex2bn(&val, buf) == 0) errx(1, "%s: illegal numeric format.", buf); @@ -159,8 +159,7 @@ /* Factor the arguments. */ else for (; *argv != NULL; ++argv) { - if (argv[0][0] == '-') - errx(1, "negative numbers aren't permitted."); + negflag = argv[0][0] == '-'; if (BN_dec2bn(&val, argv[0]) == 0 && BN_hex2bn(&val, argv[0]) == 0) errx(1, "%s: illegal numeric format.", argv[0]); @@ -187,9 +186,14 @@ if (BN_is_zero(val)) /* Historical practice; 0 just exits. */ exit(0); if (BN_is_one(val)) { - printf("1: 1\n"); + if (negflag) + printf("1: -1\n"); + else + printf("1: 1\n"); return; } + if (val < 0) + printf("-1 "); /* Factor value. */ @@ -199,6 +203,8 @@ } else BN_print_dec_fp(stdout, val); putchar(':'); + if (negflag) + fputs(" -1", stdout); for (fact = &prime[0]; !BN_is_one(val); ++fact) { /* Look for the smallest factor. */ do { --- factor.c.patch ends here --- --- factor.6.patch begins here --- --- factor.6.orig Fri Nov 29 16:21:33 2002 +++ factor.6 Mon Jan 27 06:35:26 2003 @@ -110,9 +110,10 @@ The .Ar start value is terminated by a non-digit character (such as a newline). +Negative numbers may be specified on the command line if the "--" pseudoflag +preceeds the negative argument. .Sh DIAGNOSTICS .Bl -diag -.It "negative numbers aren't permitted" .It "illegal numeric format" .It "start value must be less than stop value" .It "Result too large" --- factor.6.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message