From 355d84dba91c17d453f54e4c78ae65c8ac2c1d15 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Thu, 4 Jun 2020 11:46:30 -0400 Subject: [PATCH] fix cpplint errors --- numerical_methods/durand_kerner_roots.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/numerical_methods/durand_kerner_roots.cpp b/numerical_methods/durand_kerner_roots.cpp index dd746ad7c..030364d27 100644 --- a/numerical_methods/durand_kerner_roots.cpp +++ b/numerical_methods/durand_kerner_roots.cpp @@ -63,9 +63,10 @@ std::complex poly_function(const std::valarray &coeffs, * \returns pointer to converted string */ const char *complex_str(const std::complex &x) { - static char msg[50]; +#define MAX_BUFF_SIZE 50 + static char msg[MAX_BUFF_SIZE]; - sprintf(msg, "% 7.04g%+7.04gj", x.real(), x.imag()); + std::snprintf(msg, MAX_BUFF_SIZE, "% 7.04g%+7.04gj", x.real(), x.imag()); return msg; } @@ -148,7 +149,10 @@ int main(int argc, char **argv) { // numerical errors less when the first coefficient is "1" // hence, we normalize the first coefficient - coeffs /= coeffs[0]; + { + double tmp = coeffs[0]; + coeffs /= tmp; + } #if defined(DEBUG) || !defined(NDEBUG) log_file << "avg. correction"; @@ -157,7 +161,7 @@ int main(int argc, char **argv) { #endif double tol_condition = 1; - unsigned long iter = 0; + uint32_t iter = 0; clock_t end_time, start_time = clock(); while (!check_termination(tol_condition) && iter < INT_MAX) { @@ -220,7 +224,8 @@ end: std::cout << "\t" << complex_str(s0[n]) << "\n"; std::cout << "absolute average change: " << tol_condition << "\n"; std::cout << "Time taken: " - << (end_time - start_time) / (double)CLOCKS_PER_SEC << " sec\n"; + << static_cast(end_time - start_time) / CLOCKS_PER_SEC + << " sec\n"; return 0; -} \ No newline at end of file +}