Handbook
Glossary
sieve ( n -- sieve )
Vocabulary
math
.
primes
.
erato
Inputs
n
an
integer
Outputs
sieve
a
byte-array
Word description
Apply Eratostene sieve up to
n
.
n
must be greater than 1. Primality can then be tested using
marked-prime?
.
Definition
USING:
kernel
math
math.functions
math.primes.erato.private
ranges
sequences
;
IN:
math.primes.erato
::
sieve
( n -- sieve )
n
integer>fixnum-strict
init-sieve
:>
sieve sieve
upper-bound
>fixnum
:>
upper 3 upper
sqrt
2
<range>
[|
i |
i sieve
marked-unsafe?
[
i upper sieve
unmark-multiples
]
when
]
each
sieve
;