src/benchmark/bench_tools.h
changeset 1284 b941d044f87b
parent 921 818510fa3d99
equal deleted inserted replaced
4:489bf9f1852f 5:6a464c0ad260
    26  
    26  
    27 
    27 
    28 ///A primitive primtest
    28 ///A primitive primtest
    29 
    29 
    30 ///\bug 2 is not a prime according to this function!
    30 ///\bug 2 is not a prime according to this function!
    31 bool isPrim(int n)
    31 ///
       
    32 ///\bug This function should go out of header file. I'm making it
       
    33 /// inline for now.
       
    34 inline bool isPrim(int n)
    32 {
    35 {
    33   if(n%2) {
    36   if(n%2) {
    34     for(int k=3;n/k>=k;k+=2)
    37     for(int k=3;n/k>=k;k+=2)
    35       if(!(n%k)) return false;
    38       if(!(n%k)) return false;
    36     return true;
    39     return true;
    37   }
    40   }
    38   return false;
    41   return false;
    39 }
    42 }
    40 
    43 
    41 ///Finds the smallest prime not less then \c n.
    44 ///Finds the smallest prime not less then \c n.
    42 int nextPrim(int n)
    45 
       
    46 ///\bug This function should go out of header file. I'm making it
       
    47 /// inline for now.
       
    48 inline int nextPrim(int n)
    43 {
    49 {
    44   for(n+=!(n%2);!isPrim(n);n+=2) ;
    50   for(n+=!(n%2);!isPrim(n);n+=2) ;
    45   return n;
    51   return n;
    46 }
    52 }
    47 
    53