GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 17 / 0 / 17
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 10 / 0 / 10

src/utilities/math/Primes.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_MATH_PRIMES_HPP
7 #define UTILITIES_MATH_PRIMES_HPP
8
9 #include <cmath>
10
11 namespace openstudio {
12
13 template <class T>
14 18 bool isPrime(T val) {
15 18 bool prime = true;
16
17
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if (val < 2) {
18 2 return false;
19
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 15 times.
16 } else if (val == 2) {
20 1 return true;
21
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12 times.
15 } else if (val % 2 == 0) {
22 3 return false;
23 } else {
24 12 T divisor(3);
25 12 auto dval = static_cast<double>(val);
26 12 T upperLimit = static_cast<T>(std::sqrt(dval) + 1);
27
28
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 8 times.
23 while (divisor <= upperLimit) {
29
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11 times.
15 if (val % divisor == 0) {
30 4 prime = false;
31 4 break;
32 }
33 11 divisor += 2;
34 }
35 }
36 12 return prime;
37 }
38
39 } // namespace openstudio
40
41 #endif // UTILITIES_MATH_PRIMES_HPP
42