diff options
author | joerg <joerg@NetBSD.org> | 2010-05-15 21:22:39 +0000 |
---|---|---|
committer | joerg <joerg@NetBSD.org> | 2010-05-15 21:22:39 +0000 |
commit | dc738f052f397496c658ec837c8cf9b3510d78ca (patch) | |
tree | f4151a99c6c52b36feef63a13139563f10a3eeac /factor/factor.c | |
parent | 8603c7aa19131a678587db53c982724c59f27cc9 (diff) | |
download | bsdgames-darwin-dc738f052f397496c658ec837c8cf9b3510d78ca.tar.gz bsdgames-darwin-dc738f052f397496c658ec837c8cf9b3510d78ca.tar.zst bsdgames-darwin-dc738f052f397496c658ec837c8cf9b3510d78ca.zip |
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 (limited to 'factor/factor.c')
-rw-r--r-- | factor/factor.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/factor/factor.c b/factor/factor.c index cc6c8b98..10de005d 100644 --- a/factor/factor.c +++ b/factor/factor.c @@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\ #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 @@ main(int argc, char *argv[]) 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 @@ pr_fact(BIGNUM *val) 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. */ |