]> gitweb.factorcode.org Git - factor.git/commitdiff
math.primes: fix "11 >bignum prime?".
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 16 Jun 2015 06:02:39 +0000 (23:02 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 16 Jun 2015 06:02:39 +0000 (23:02 -0700)
basis/math/primes/primes-tests.factor
basis/math/primes/primes.factor

index 22d3bcc7ba88fc19b0824eabdc32dda951931f01..d5d1cb2f328122fde58073ce8307dbe3f62cb324 100644 (file)
@@ -39,3 +39,5 @@ IN: math.primes.tests
 
 [ 5 t { 14 14 14 14 14 } ]
 [ 5 15 unique-primes [ length ] [ [ prime? ] all? ] [ [ log2 ] map ] tri ] unit-test
+
+{ t t } [ 11 dup >bignum [ prime? ] bi@ ] unit-test
index f0b4e57a9931511649fb995d521e952979af194a..642f8ef8e4b5a74d48f3aca153a15c4eb59b78e5 100644 (file)
@@ -9,12 +9,13 @@ IN: math.primes
 <PRIVATE
 
 : look-in-bitmap ( n -- ? )
-    $[ 8999999 sieve ] marked-unsafe? ; inline
+    integer>fixnum $[ 8999999 sieve ] marked-unsafe? ; inline
 
 : (prime?) ( n -- ? )
     dup 8999999 <= [ look-in-bitmap ] [ miller-rabin ] if ;
 
-: simple? ( n -- ? ) { [ even? ] [ 3 divisor? ] [ 5 divisor? ] } 1|| ;
+: simple? ( n -- ? )
+    { [ even? ] [ 3 divisor? ] [ 5 divisor? ] } 1|| ;
 
 PRIVATE>
 
@@ -37,10 +38,12 @@ PRIVATE>
 : <primes-range> ( low high -- range )
     [ 3 max dup even? [ 1 + ] when ] dip 2 <range> ;
 
-! In order not to reallocate large vectors, we compute the upper bound
-! of the number of primes in a given interval. We use a double inequality given
-! by Pierre Dusart in http://www.ams.org/mathscinet-getitem?mr=99d:11133
-! for x > 598. Under this limit, we know that there are at most 108 primes.
+! In order not to reallocate large vectors, we compute the upper
+! bound of the number of primes in a given interval. We use a
+! double inequality given by Pierre Dusart in
+! http://www.ams.org/mathscinet-getitem?mr=99d:11133 for x >
+! 598. Under this limit, we know that there are at most 108
+! primes.
 : upper-pi ( x -- y )
     dup log [ / ] [ 1.2762 swap / 1 + ] bi * ceiling ;