Skip to content

Commit 2bb96cf

Browse files
committed
[finfuns]: Tweaking workflow - fix warnings
1 parent 9901d82 commit 2bb96cf

14 files changed

Lines changed: 107 additions & 39 deletions

File tree

.clang-tidy

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
HeaderFilterRegex: '^.*/(include)/.*(h|hpp)$'
1+
HeaderFilterRegex: '^(?!.*extern/).*/(include|src|test)/.*'
22

33
Checks: [
44
'*',
@@ -125,7 +125,6 @@ CheckOptions:
125125
readability-identifier-naming.EnumCase: CamelCase
126126
readability-identifier-naming.LocalVariableCase: lower_case
127127
readability-identifier-naming.StaticConstantCase: aNy_CasE
128-
readability-identifier-naming.MemberCase: lower_case
129128
readability-identifier-naming.PrivateMemberPrefix: ''
130129
readability-identifier-naming.ProtectedMemberPrefix: ''
131130
readability-identifier-naming.PublicMemberCase: lower_case
@@ -146,4 +145,3 @@ CheckOptions:
146145
cppcoreguidelines-avoid-do-while.IgnoreMacros: true
147146
readability-identifier-naming.MemberCase: lower_case
148147
readability-identifier-naming.MemberPrefix: '_'
149-

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"name": "clang-tidy",
3535
"hidden": true,
3636
"cacheVariables": {
37-
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--header-filter=^(${sourceDir}|${sourceDir}/../extern/expected)"
37+
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--config-file=${sourceDir}/.clang-tidy;--system-headers=false"
3838
}
3939
},
4040
{

include/finfuns/day_count.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum class DayCountConvention : int32_t
2525
ACT_365_25,
2626
};
2727

28-
inline constexpr std::string_view day_count_to_string(DayCountConvention dcc)
28+
constexpr std::string_view day_count_to_string(DayCountConvention dcc)
2929
{
3030
switch (dcc)
3131
{
@@ -40,18 +40,18 @@ inline constexpr std::string_view day_count_to_string(DayCountConvention dcc)
4040

4141

4242
template <ChronoDayType D>
43-
inline constexpr auto days_between_act(D d1, D d2)
43+
constexpr auto days_between_act(D d1, D d2)
4444
{
4545
return (d2 - d1).count();
4646
}
4747

48-
inline constexpr int days_between_act(int d1, int d2)
48+
constexpr int days_between_act(int d1, int d2)
4949
{
5050
return d2 - d1;
5151
}
5252

5353
template <DayCountConvention dcc, typename D>
54-
inline constexpr double year_fraction(D d1, D d2)
54+
constexpr double year_fraction(D d1, D d2)
5555
{
5656
if constexpr (dcc == DayCountConvention::ACT_365F)
5757
return static_cast<double>(days_between_act(d1, d2)) / 365.0;

include/finfuns/irr.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum class IRRErrorCode : int32_t
2626

2727
using IRRError = std::variant<IRRErrorCode, SolverErrorCode>;
2828

29-
inline constexpr std::string_view error_to_sv(IRRErrorCode error)
29+
constexpr std::string_view error_to_sv(IRRErrorCode error)
3030
{
3131
switch (error)
3232
{
@@ -39,7 +39,7 @@ inline constexpr std::string_view error_to_sv(IRRErrorCode error)
3939
}
4040
}
4141

42-
inline constexpr std::string_view error_to_sv(const IRRError & error)
42+
constexpr std::string_view error_to_sv(const IRRError & error)
4343
{
4444
return std::visit([](const auto & e) { return error_to_sv(e); }, error);
4545
}

include/finfuns/npv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ enum class NPVError : int32_t
2323
EmptyCashflows, //!< cashflows.empty()
2424
};
2525

26-
inline constexpr std::string_view error_to_sv(NPVError error)
26+
constexpr std::string_view error_to_sv(NPVError error)
2727
{
2828
switch (error)
2929
{

include/finfuns/rate_solver.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enum class SolverErrorCode
2727
OTHER_ERROR
2828
};
2929

30-
inline constexpr std::string_view error_to_sv(SolverErrorCode error)
30+
constexpr std::string_view error_to_sv(SolverErrorCode error)
3131
{
3232
switch (error)
3333
{
@@ -52,7 +52,7 @@ struct CachedFunction
5252
double _last_rate = std::numeric_limits<double>::quiet_NaN();
5353
std::pair<double, double> _last_result;
5454

55-
CachedFunction(Calculator & c)
55+
explicit CachedFunction(Calculator & c)
5656
: _calculator{c}
5757
{
5858
}

include/finfuns/xirr.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum class XIRRErrorCode : int32_t
2828

2929
using XIRRError = std::variant<XIRRErrorCode, SolverErrorCode>;
3030

31-
inline constexpr std::string_view error_to_sv(XIRRErrorCode error)
31+
constexpr std::string_view error_to_sv(XIRRErrorCode error)
3232
{
3333
switch (error)
3434
{
@@ -45,7 +45,7 @@ inline constexpr std::string_view error_to_sv(XIRRErrorCode error)
4545
}
4646
}
4747

48-
inline constexpr std::string_view error_to_sv(const XIRRError & error)
48+
constexpr std::string_view error_to_sv(const XIRRError & error)
4949
{
5050
return std::visit([](const auto & e) { return error_to_sv(e); }, error);
5151
}

include/finfuns/xnpv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum class XNPVError : int32_t
2626
UnsupportedDayCountConvention, //!< unsupported day count convention
2727
};
2828

29-
inline constexpr std::string_view error_to_sv(XNPVError error)
29+
constexpr std::string_view error_to_sv(XNPVError error)
3030
{
3131
switch (error)
3232
{

lib/finfunslib/finfunslib.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ FINFUNSLIB_EXPORT double finfuns_fv_due_end(double rate, uint32_t periods, doubl
8585
*/
8686
FINFUNSLIB_EXPORT double finfuns_fv_due_begin(double rate, uint32_t periods, double pmt, double present_value) noexcept;
8787

88+
// NOLINTBEGIN
8889
/**
8990
* @brief Error codes for finfuns calculations
9091
*
@@ -113,7 +114,7 @@ typedef enum
113114
// Unexpected error
114115
FINFUNS_CODE_UNEXPECTED_ERROR = 999,
115116
} FinFunsCode;
116-
117+
// NOLINTEND
117118

118119
/**
119120
* @brief Calculates Internal Rate of Return (IRR)
@@ -130,8 +131,9 @@ typedef enum
130131
* @warning The first cashflow should typically be negative (initial investment).
131132
*/
132133
FINFUNSLIB_EXPORT [[nodiscard]] FinFunsCode
133-
finfuns_irr(const double * cashflows, int num_cashflows, double guess, double * out_result) noexcept;
134+
finfuns_irr(const double * cashflows, unsigned num_cashflows, double guess, double * out_result) noexcept;
134135

136+
// NOLINTBEGIN
135137
/**
136138
* @brief Time period indexing convention
137139
*/
@@ -140,6 +142,7 @@ typedef enum
140142
FINFUNS_ZERO_BASED, ///< First period is index 0 (standard financial convention)
141143
FINFUNS_ONE_BASED ///< First period is index 1 (alternative convention)
142144
} FinFunsIndexMode;
145+
// NOLINTEND
143146

144147
/**
145148
* @brief Calculate Net Present Value (NPV)
@@ -156,9 +159,10 @@ typedef enum
156159
* For OneBased mode, all cashflows are discounted (first occurs at t=1).
157160
*/
158161
FINFUNSLIB_EXPORT [[nodiscard]] FinFunsCode
159-
finfuns_npv(FinFunsIndexMode mode, double rate, const double * cashflows, int num_cashflows, double * out_result) noexcept;
162+
finfuns_npv(FinFunsIndexMode mode, double rate, const double * cashflows, unsigned num_cashflows, double * out_result) noexcept;
160163

161164

165+
// NOLINTBEGIN
162166
/**
163167
* @brief Day count conventions
164168
*/
@@ -167,6 +171,7 @@ typedef enum
167171
FINFUNS_ACT_365F, ///< Actual days / 365-day year (ISDA)
168172
FINFUNS_ACT_365_25, ///< Actual days / 365.25-day year (ISDA)
169173
} FinFunsDayCount;
174+
// NOLINTEND
170175

171176
/**
172177
* @brief Calculates XNPV with dates as days since epoch (1970-01-01). Could also jus use relative days if the given date convention supports it.
@@ -183,7 +188,12 @@ typedef enum
183188
* @warning First cashflow (typically the investment) should be negative
184189
*/
185190
FINFUNSLIB_EXPORT [[nodiscard]] FinFunsCode finfuns_xnpv(
186-
FinFunsDayCount day_count, double rate, const double * cashflows, const int * dates, int num_cashflows, double * out_result) noexcept;
191+
FinFunsDayCount day_count,
192+
double rate,
193+
const double * cashflows,
194+
const int * dates,
195+
unsigned num_cashflows,
196+
double * out_result) noexcept;
187197

188198
/**
189199
* @brief Calculates XIRR with dates as days since epoch (1970-01-01). Could also jus use relative days if the given date convention supports it.
@@ -201,7 +211,12 @@ FINFUNSLIB_EXPORT [[nodiscard]] FinFunsCode finfuns_xnpv(
201211
* @warning First cashflow should typically be negative (initial investment)
202212
*/
203213
FINFUNSLIB_EXPORT [[nodiscard]] FinFunsCode finfuns_xirr(
204-
FinFunsDayCount day_count, const double * cashflows, const int * dates, int num_cashflows, double guess, double * out_result) noexcept;
214+
FinFunsDayCount day_count,
215+
const double * cashflows,
216+
const int * dates,
217+
unsigned num_cashflows,
218+
double guess,
219+
double * out_result) noexcept;
205220

206221

207222
#ifdef __cplusplus

lib/finfunslib/src/finfunslib.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ double finfuns_fv_due_begin(double rate, uint32_t periods, double pmt, double pr
119119
return fv<PaymentDueType::BeginningOfPeriod>(rate, periods, pmt, present_value);
120120
}
121121

122-
FinFunsCode finfuns_irr(const double * cashflows, int num_cashflows, double guess, double * out_result) noexcept
122+
FinFunsCode finfuns_irr(const double * cashflows, unsigned num_cashflows, double guess, double * out_result) noexcept
123123
{
124124
const auto cf_span = std::span<const double>(cashflows, num_cashflows);
125125
auto result = irr(cf_span, guess);
@@ -133,7 +133,7 @@ FinFunsCode finfuns_irr(const double * cashflows, int num_cashflows, double gues
133133
return error_code;
134134
}
135135

136-
FinFunsCode finfuns_npv(FinFunsIndexMode mode, double rate, const double * cashflows, int num_cashflows, double * out_result) noexcept
136+
FinFunsCode finfuns_npv(FinFunsIndexMode mode, double rate, const double * cashflows, unsigned num_cashflows, double * out_result) noexcept
137137
{
138138
const auto cf_span = std::span{cashflows, static_cast<size_t>(num_cashflows)};
139139
auto result = (mode == FINFUNS_ZERO_BASED) ? npv<IndexMode::ZeroBased>(rate, cf_span) : npv<IndexMode::OneBased>(rate, cf_span);
@@ -147,7 +147,12 @@ FinFunsCode finfuns_npv(FinFunsIndexMode mode, double rate, const double * cashf
147147
}
148148

149149
FINFUNSLIB_EXPORT FinFunsCode finfuns_xnpv(
150-
FinFunsDayCount day_count, double rate, const double * cashflows, const int * dates, int num_cashflows, double * out_result) noexcept
150+
FinFunsDayCount day_count,
151+
double rate,
152+
const double * cashflows,
153+
const int * dates,
154+
unsigned num_cashflows,
155+
double * out_result) noexcept
151156
{
152157
const auto cf_span = std::span(cashflows, num_cashflows);
153158
const auto date_span = std::span(dates, num_cashflows);
@@ -173,7 +178,12 @@ FINFUNSLIB_EXPORT FinFunsCode finfuns_xnpv(
173178
}
174179

175180
FINFUNSLIB_EXPORT FinFunsCode finfuns_xirr(
176-
FinFunsDayCount day_count, const double * cashflows, const int * dates, int num_cashflows, double guess, double * out_result) noexcept
181+
FinFunsDayCount day_count,
182+
const double * cashflows,
183+
const int * dates,
184+
unsigned num_cashflows,
185+
double guess,
186+
double * out_result) noexcept
177187
{
178188
const auto cf_span = std::span(cashflows, num_cashflows);
179189
const auto date_span = std::span(dates, num_cashflows);

0 commit comments

Comments
 (0)