/* 1 1 check primeness of small numbers isprime uses an inefficient brute-force method, checking for divisibility by all possible divisors. It should only be used to check for primeness of relatively small numbers. */ double nf_isprime(const Node *n, const Cell *c) { Node *r = n->u.t.right; double d; int i, j, k; i = d = eval_tree( r, c); if( i != d || i < 0) { fprintf( out, "isprime: argument must be integer >= 0\n"); return 0; } if( i < 2) return 0; if( i < 4) return 1; if( !(i & 1)) return 0; /* not odd */ k = i/2; for( j = 3; j <= k; j += 2) if( i % j == 0) return 0; return 1; }