Effective implementation of algorithms (Master Thesis)
Effective and error-free implementation of algorithms
src/math/primes/primes_slow.h
Go to the documentation of this file.
00001 #ifndef H_MATH_PRIMES_PRIMES_SLOW
00002 #define H_MATH_PRIMES_PRIMES_SLOW
00003 
00009 #include "utils/preconditions/preconditions.h"
00010 #include "utils/static_assert/static_assert.h"
00011 #include <limits>
00012 
00013 namespace math {
00014 namespace primes {
00015 
00022 class PrimesSlow {
00023 public:
00033   template <typename BaseType>
00034   bool static isPrime(BaseType p) {
00035     STATIC_ASSERT(std::numeric_limits<BaseType>::is_integer, 
00036         "BaseType should be integer");
00037     Preconditions::check(p > 0, "tested integer should be positive");
00038     if (p == 1) {
00039       return false;
00040     }
00041     for (BaseType i = 2; i < p; i++) {
00042       if (p % i == 0) {
00043         return false;
00044       }
00045     }
00046     return true;
00047   }
00048 };
00049 
00050 } // namespace primes
00051 } // namespace math
00052 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines