added primes.h/.cpp (contains precomputed primes)

This commit is contained in:
Michael Hemmer 2008-03-31 12:50:54 +00:00
parent f60be6045d
commit ef862d658e
3 changed files with 57 additions and 0 deletions

View File

@ -23,3 +23,4 @@
#include "Real_timer.cpp"
#include "Timer.cpp"
#include "Turkowski_numeric_solver.cpp"
#include "primes.cpp"

View File

@ -0,0 +1,45 @@
#ifndef CGAL_PRIMES_H
#define CGAL_PRIMES_H
#include <CGAL/basic.h>
namespace CGAL {
namespace CGALi {
extern int primes[2000];
static inline
int get_next_lower_prime(int current_prime){
bool is_prime = false;
int i;
CGAL_precondition_msg(current_prime != 2 ," primes definitely exhausted ");
if((current_prime <= 7) && (current_prime > 2)){
if(current_prime <= 5){
if(current_prime == 3)
return 2;
return 3;
}
return 5;
}
for(i=current_prime-2;(i>1 && !is_prime);i=i-2){
int r = 1;
for(int j=3; (j <= i/2 && (r != 0)); j++){
r = i % j;
// std::cout<<"i " <<i<<std::endl;
// std::cout<<"j " <<j<<std::endl;
// std::cout<<"i%j " <<i%j<<std::endl;
if(j==i/2 && r != 0)
is_prime = true;
}
}
// CGAL_precondition_msg(is_prime," primes definitely exhausted ");
return i+2;
}
}
}
#endif // CGAL_PRIMES_H

File diff suppressed because one or more lines are too long