GCC Code Coverage Report
Directory: cmake-example-component-lib Exec Total Coverage
File: standalone/source/calc.cxx Lines: 17 21 81.0 %
Date: 2021-03-15 07:36:42 Branches: 3 10 30.0 %

Line Branch Exec Source
1
//
2
// A very simple calculator
3
//
4
#include <fmt/core.h>
5
#include <mathfunctions/MathFunctions.h>
6
7
#include <exception>
8
#include <iostream>
9
#include <string>
10
11
1
auto main(int argc, char* argv[]) -> int {
12
1
  if (argc < 2) {
13
    fmt::print(stderr, "Usage: {} number\n", *argv);
14
    return 0;  // Note: not an error, just a hint ;-)
15
  }
16
17
  // convert input to double
18
1
  double inputValue{1.0};
19
  try {
20

1
    inputValue = std::stod(argv[1]);  // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
21
1
  } catch (const std::exception& e) {
22
    fmt::print(stderr, "Oops: {}; this is not valid number: {}!\n", e.what(), argv[1]);
23
    return 0;
24
  }
25
26
  // calculate square root
27
1
  const double sqrt = MathFunctions::sqrt(inputValue);
28
1
  fmt::print("The square root of {} is {}\n", inputValue, sqrt);
29
30
  // calculate sum
31
1
  const double sum = MathFunctions::add(inputValue, inputValue);
32
1
  fmt::print("{0} + {0} = {1}\n", inputValue, sum);
33
34
  // calculate difference
35
1
  const double dif = MathFunctions::dif(inputValue, inputValue);
36
1
  fmt::print("{0} - {0} = {1}\n", inputValue, dif);
37
38
  // calculate product
39
1
  const double mul = MathFunctions::mul(inputValue, inputValue);
40
1
  fmt::print("{0} * {0} = {1}\n", inputValue, mul);
41
42
  // calculate quotient
43
1
  const double quo = MathFunctions::quo(inputValue, inputValue);
44
1
  fmt::print("{0} / {0} = {1}\n", inputValue, quo);
45
46
1
  return 0;
47
1
}