GCC Code Coverage Report


Directory: Utils/
File: Algorithms.cpp
Date: 2026-11-03 21:19:32
Exec Total Coverage
Lines: 15 15 100.0%
Functions: 2 2 100.0%
Branches: 5 8 62.5%

Line Branch Exec Source
1 // ======================================================================
2 // \title Algorithms.cpp
3 // \author sjsreehari
4 // \brief cpp file for general-purpose mathematical algorithms
5 //
6 // \copyright
7 // Copyright (C) 2026 California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 // ======================================================================
11
12 #include <Fw/Types/Assert.hpp>
13 #include <Utils/Algorithms.hpp>
14 #include <limits>
15
16 namespace Utils {
17 namespace Algorithms {
18
19 14 FwSizeType gcd(FwSizeType a, FwSizeType b) {
20 14 const FwSizeType maxIterations = static_cast<FwSizeType>(std::numeric_limits<FwSizeType>::digits) * 2;
21
3/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 14 times.
42 for (FwSizeType i = 0; (i < maxIterations) && (b != 0); i++) {
22 28 FwSizeType temp = b;
23
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 b = a % b;
24 28 a = temp;
25 }
26 14 FW_ASSERT(b == 0);
27 14 return a;
28 }
29
30 6 FwSizeType lcm(FwSizeType a, FwSizeType b) {
31 6 FW_ASSERT(a != 0);
32 6 FW_ASSERT(b != 0);
33 6 const FwSizeType g = gcd(a, b);
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 const FwSizeType a_div_g = a / g;
35 // Ensure that lcm will not overflow
36 6 FW_ASSERT((std::numeric_limits<FwSizeType>::max() / b) >= a_div_g, static_cast<FwAssertArgType>(a),
37 static_cast<FwAssertArgType>(b));
38 6 return a_div_g * b;
39 }
40
41 } // namespace Algorithms
42 } // namespace Utils
43