commit d4769be05a6abf888eea3cc7fc2066756de874ef Author: John Denker Date: Fri Feb 1 11:03:35 2013 -0700 return results of monicPoly and Poly; also get rid of some meaningless warnings diff --git a/brent.cpp b/brent.cpp index da28491..2eedf4d 100644 --- a/brent.cpp +++ b/brent.cpp @@ -1028,22 +1028,20 @@ void timestamp ( ) // None // { -# define TIME_SIZE 40 + const int TIME_SIZE(40); static char time_buffer[TIME_SIZE]; const struct tm *tm; - size_t len; time_t now; now = time ( NULL ); tm = localtime ( &now ); - len = strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); + strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); cout << time_buffer << "\n"; return; -# undef TIME_SIZE } //****************************************************************************80 @@ -1506,6 +1504,7 @@ double monicPoly::operator()(double x){ rslt *= x; rslt += coeff[ii]; } + return rslt; } // Similarly, evaluate a general polynomial (not necessarily monic): @@ -1515,6 +1514,7 @@ double Poly::operator()(double x){ rslt *= x; rslt += coeff[ii]; } + return rslt; } } // end namespace brent commit 6e4144022dd3ccf1e743cab6439a56138f871914 Author: John Denker Date: Fri Feb 1 11:56:51 2013 -0700 automatically detect numerical errors diff --git a/brent_prb.cpp b/brent_prb.cpp index 6dc9d3b..bff12fb 100644 --- a/brent_prb.cpp +++ b/brent_prb.cpp @@ -9,7 +9,7 @@ using namespace std; using namespace brent; -int main ( ); +const double check_tolerance(1e-15); void test_zero_all ( ); void test_zero_rc_all ( ); @@ -530,6 +530,13 @@ void test_zero_one ( double a, double b, double t, double f ( double x ), << " " << setw(14) << fz << " " << setw(14) << fb << "\n"; + if (abs(fz) > check_tolerance) { + cerr << "*** error ***" << endl; + cerr << "fz " << fz + << " exceeds check_tolerance " << check_tolerance << endl; + exit(1); + } + return; } //****************************************************************************80 @@ -605,9 +612,16 @@ void test_zero_rc_one ( double a, double b, double t, double f ( double x ), break; } } + if (abs(value) > check_tolerance) { + cerr << "*** error ***" << endl; + cerr << "final value " << value + << " exceeds check_tolerance " << check_tolerance << endl; + exit(1); + } return; } + //****************************************************************************80 template