Host C Specs


Directory: src/c/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 5 / 0 / 5
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 4 / 0 / 4

core/math/pct.c
Line Branch Exec Source
1 /**
2 * @file pct.c
3 * @brief Progress towards a goal, as a percent.
4 *
5 * @ingroup lib_core
6 */
7 #include "math/pct.h"
8
9 8 int pct_of(int value, int goal)
10 {
11
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 times.
8 if (goal <= 0 || value <= 0)
12 {
13 4 return 0;
14 }
15
16 4 int pct = (value * 100) / goal;
17 4 return pct > 100 ? 100 : pct;
18 }
19