summaryrefslogtreecommitdiffstats
path: root/primes
diff options
context:
space:
mode:
authorjakllsch <jakllsch@NetBSD.org>2011-08-30 02:58:04 +0000
committerjakllsch <jakllsch@NetBSD.org>2011-08-30 02:58:04 +0000
commit8fdb2354b50bedf84e0744346e974d308ded6a1b (patch)
tree9b6b7c4ad53e41341d9681e301941931e05e9ce5 /primes
parentb9729f21ecee00f10aeb911143988ae326aa17b7 (diff)
downloadbsdgames-darwin-8fdb2354b50bedf84e0744346e974d308ded6a1b.tar.gz
bsdgames-darwin-8fdb2354b50bedf84e0744346e974d308ded6a1b.tar.zst
bsdgames-darwin-8fdb2354b50bedf84e0744346e974d308ded6a1b.zip
No need to cast double to ubig (aka uintmax_t) through int.
This change prevents a modulo by zero in a invocation such as: primes 18446744073709551000 18446744073709551615 on a LP64 machine.
Diffstat (limited to 'primes')
-rw-r--r--primes/primes.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/primes/primes.c b/primes/primes.c
index c8c6ea58..5952bbf6 100644
--- a/primes/primes.c
+++ b/primes/primes.c
@@ -1,4 +1,4 @@
-/* $NetBSD: primes.c,v 1.18 2010/05/13 17:52:12 tnozaki Exp $ */
+/* $NetBSD: primes.c,v 1.19 2011/08/30 02:58:04 jakllsch Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
#if 0
static char sccsid[] = "@(#)primes.c 8.5 (Berkeley) 5/10/95";
#else
-__RCSID("$NetBSD: primes.c,v 1.18 2010/05/13 17:52:12 tnozaki Exp $");
+__RCSID("$NetBSD: primes.c,v 1.19 2011/08/30 02:58:04 jakllsch Exp $");
#endif
#endif /* not lint */
@@ -305,11 +305,10 @@ primes(ubig start, ubig stop)
/* note highest useful factor and sieve spot */
if (stop-start > TABSIZE+TABSIZE) {
tab_lim = &table[TABSIZE]; /* sieve it all */
- fact_lim = (int)sqrt(
- (double)(start)+TABSIZE+TABSIZE+1.0);
+ fact_lim = sqrt((double)(start)+TABSIZE+TABSIZE+1.0);
} else {
tab_lim = &table[(stop-start)/2]; /* partial sieve */
- fact_lim = (int)sqrt((double)(stop)+1.0);
+ fact_lim = sqrt((double)(stop)+1.0);
}
/* sieve for factors >= 17 */
factor = 17; /* 17 is first prime to use */