BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/primes.h
Go to the documentation of this file.
00001 // Copyright (c) 2006-2007 Max-Planck-Institute Saarbruecken (Germany).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Modular_arithmetic/include/CGAL/primes.h $
00016 // $Id: primes.h 45608 2008-09-17 07:47:12Z hemmer $
00017 //
00018 //
00019 // Author(s)     : Michael Hemmer    <hemmer@mpi-inf.mpg.de>
00020 //
00021 // =============================================================================
00022 
00023 #ifndef CGAL_PRIMES_H
00024 #define CGAL_PRIMES_H
00025 
00026 #include <CGAL/basic.h>
00027 
00028 namespace CGAL { 
00029 namespace CGALi {
00030 extern int primes[2000];
00031 
00032 static inline 
00033 int get_next_lower_prime(int current_prime){
00034     bool is_prime = false;
00035     
00036     int i;
00037     CGAL_precondition_msg(current_prime != 2 ," primes definitely exhausted ");
00038 
00039     if((current_prime <= 7) && (current_prime > 2)){
00040         if(current_prime <= 5){
00041             if(current_prime == 3)
00042                 return 2;
00043             return 3;
00044         }
00045         return 5;
00046     }                
00047     for(i=current_prime-2;(i>1 && !is_prime);i=i-2){
00048         int r = 1;
00049         for(int j=3; (j <= i/2 && (r != 0)); j++){
00050             r = i % j;
00051 //                std::cout<<"i " <<i<<std::endl;
00052 //                std::cout<<"j " <<j<<std::endl;
00053 //                std::cout<<"i%j " <<i%j<<std::endl;
00054             if(j==i/2 && r != 0)
00055                 is_prime = true;
00056         }
00057     }
00058 //    CGAL_precondition_msg(is_prime," primes definitely exhausted ");
00059     return i+2;
00060 }
00061 
00062 
00063 }
00064 }
00065 
00066 #endif // CGAL_PRIMES_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines