diff scripts/specfun/isprime.m @ 11469:c776f063fefe

Overhaul m-script files to use common variable name between code and documentation.
author Rik <octave@nomad.inbox5.com>
date Sun, 09 Jan 2011 12:41:21 -0800
parents 0d9640d755b1
children fd0a3ac60b0e
line wrap: on
line diff
--- a/scripts/specfun/isprime.m	Sun Jan 09 21:24:43 2011 +0100
+++ b/scripts/specfun/isprime.m	Sun Jan 09 12:41:21 2011 -0800
@@ -34,20 +34,20 @@
 ## @seealso{primes, factor, gcd, lcm}
 ## @end deftypefn
 
-function t = isprime (n)
+function t = isprime (x)
 
   if (nargin == 1)
-    if (any ((n != floor (n) | n < 0)(:)))
+    if (any ((x != floor (x) | x < 0)(:)))
       error ("isprime: needs positive integers");
     endif
-    maxn = max (n(:));
+    maxn = max (x(:));
     ## generate prime table of suitable length.
     maxp = min (maxn, max (sqrt (maxn), 1e7)); # FIXME: threshold not optimized.
     pr = primes (maxp);
     ## quick search for table matches.
-    t = lookup (pr, n, "b");
+    t = lookup (pr, x, "b");
     ## take the rest.
-    m = n(n > maxp);
+    m = x(x > maxp);
     if (! isempty (m))
       ## there are still possible primes. filter them out by division.
       if (maxn <= intmax ("uint32"))
@@ -68,8 +68,8 @@
       mm = arrayfun (@(x) all (rem (x, pr)), m);
       m = m(mm);
       if (! isempty (m))
-        m = cast (sort (m), class (n));
-        t |= lookup (m, n, "b");
+        m = cast (sort (m), class (x));
+        t |= lookup (m, x, "b");
       endif
     endif
 
@@ -79,6 +79,7 @@
 
 endfunction
 
+
 %!assert (isprime (4), logical (0));
 %!assert (isprime (3), logical (1));
 %!assert (isprime (magic (3)), logical ([0, 0, 0; 1, 1, 1; 0, 0, 1]));