From 3b37d06d2a3ed215ff896da75a5204cf5dfa9ddf Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Thu, 4 Jun 2020 13:37:34 -0400 Subject: [PATCH] use INT16_MAX --- numerical_methods/durand_kerner_roots.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/numerical_methods/durand_kerner_roots.cpp b/numerical_methods/durand_kerner_roots.cpp index b49a2cef6..90789fd4d 100644 --- a/numerical_methods/durand_kerner_roots.cpp +++ b/numerical_methods/durand_kerner_roots.cpp @@ -100,7 +100,7 @@ std::pair durand_kerner_algo( std::valarray> *roots, bool write_log = false) { double tol_condition = 1; uint32_t iter = 0; - int i, n, degree = coeffs.size(); + int i, n; std::ofstream log_file; if (write_log) { @@ -114,15 +114,15 @@ std::pair durand_kerner_algo( } log_file << "iter#,"; - for (n = 0; n < degree - 1; n++) log_file << "root_" << n << ","; + for (n = 0; n < roots->size(); n++) log_file << "root_" << n << ","; log_file << "avg. correction"; log_file << "\n0,"; - for (n = 0; n < degree - 1; n++) + for (n = 0; n < roots->size(); n++) log_file << complex_str((*roots)[n]) << ","; } - while (!check_termination(tol_condition) && iter < INT_MAX) { + while (!check_termination(tol_condition) && iter < INT16_MAX) { std::complex delta = 0; tol_condition = 0; iter++; @@ -133,11 +133,11 @@ std::pair durand_kerner_algo( #ifdef _OPENMP #pragma omp for #endif - for (n = 0; n < degree - 1; n++) { + for (n = 0; n < roots->size(); n++) { std::complex numerator, denominator; numerator = poly_function(coeffs, (*roots)[n]); denominator = 1.0; - for (i = 0; i < degree - 1; i++) + for (i = 0; i < roots->size(); i++) if (i != n) denominator *= (*roots)[n] - (*roots)[i]; @@ -161,7 +161,7 @@ std::pair durand_kerner_algo( #if defined(DEBUG) || !defined(NDEBUG) if (iter % 500 == 0) { std::cout << "Iter: " << iter << "\t"; - for (n = 0; n < degree - 1; n++) + for (n = 0; n < roots->size(); n++) std::cout << "\t" << complex_str((*roots)[n]); std::cout << "\t\tabsolute average change: " << tol_condition << "\n";