1 #include <stdlib.h>
2 #include "testprime.h"
3 
4 /*----- max value of nnn is 2^31-1 so max value of pp is 46337 -----*/
5 
test_prime(int nnn)6 int test_prime( int nnn )
7 {
8    register int ii , pp , np , nloc ;
9 
10    if( nnn <= 0 ) return -1 ;
11    if( nnn == 1 ) return  0 ;
12    np   = NUMplist ;
13    nloc = nnn ;
14    for( ii=0 ; ii < np ; ii++ ){
15      pp = (int)plist[ii] ;
16      if( pp*pp      > nloc ) return 1 ; /* not divisible by prime <= sqrt(nloc) */
17      if( nloc % pp == 0    ) return 0 ; /* divisible by this prime */
18 #if 0
19      if( pp        == nloc ) return 1 ; /* equals this prime */
20 #endif
21    }
22    return 1 ; /* should not be reached */
23 }
24 
25 /*----- function called by parser.f -----*/
26 
isprime_(double xxx)27 double isprime_( double xxx )
28 {
29    int nnn = (int)rint(xxx) ;
30 
31    if( fabs(xxx-(double)nnn) > 0.001 ) return -1.0 ;
32 
33    return (double)test_prime(nnn) ;
34 }
35