prevprime, nextprime
Mads Jensen <[email protected]> Wed, 15 Oct 2008 19:14:07 +0200
| Newsgroups | gmane.comp.gnu.octave.sources |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
The following two subroutines are availble in Maple, and I thought it'd
be useful to include them in Octave, too. I'm a new to Octave, so they
may be written more succintly
function m = prevprime(n)
tmp = n-1;
stmp = n-1000;
if isprime(n-1)
m = tmp;
return
endif
while(i>stmp)
if isprime(i)
m = i;
return
endif
endwhile
endfunction
function m = nextprime(n)
tmp = n+1;
ltmp = tmp + 1000;
if isprime(tmp)
m = tmp;
return
endif
for i=tmp:ltmp
if isprime(i)
m=i;
return
endif
endfor
endfunction
Kind regards,
Mads Jensen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkj2JN8ACgkQPOK1Nn53W9p9hACeLqQe38/gh2Tkg0EGrH4tWGzm
jFYAnjiwr4vMfJrZ6vz0pgL4r0S7btzM
=n8Em
-----END PGP SIGNATURE-----