# include # include # include # include # include using namespace std; # include "machar.hpp" int main ( ); void r4_machar_test ( ); void r8_machar_test ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // machar_test() tests machar(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 11 November 2006 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "MACHAR_TEST():\n"; cout << " C++ version\n"; cout << " Test MACHAR().\n"; r4_machar_test ( ); r8_machar_test ( ); // // Terminate. // cout << "\n"; cout << "MACHAR_TEST():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void r4_machar_test ( ) //****************************************************************************80 // // Purpose: // // R4_MACHAR_TEST tests R4_MACHAR. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 April 2007 // // Author: // // John Burkardt // { float eps; float epsneg; long int ibeta; long int iexp; long int irnd; long int it; long int machep; long int maxexp; long int minexp; long int negep; long int ngrd; float xmax; float xmin; cout << "\n"; cout << "R4_MACHAR_TEST\n"; cout << " R4_MACHAR computes single\n"; cout << " precision machine constants.\n"; r4_machar ( &ibeta, &it, &irnd, &ngrd, &machep, &negep, &iexp, &minexp, &maxexp, &eps, &epsneg, &xmin, &xmax ); cout << "\n"; cout << " IBETA = " << ibeta << "\n"; cout << " IT = " << it << "\n"; cout << " IRND = " << irnd << "\n"; cout << " NGRD = " << ngrd << "\n"; cout << " MACHEP = " << machep << "\n"; cout << " NEGEP = " << negep << "\n"; cout << " IEXP = " << iexp << "\n"; cout << " MINEXP = " << minexp << "\n"; cout << " MAXEXP = " << maxexp << "\n"; cout << setw(26) << setprecision(16) << " EPS = " << eps << "\n"; cout << setw(26) << setprecision(16) << " EPSNEG = " << epsneg << "\n"; cout << setw(26) << setprecision(16) << " XMIN = " << xmin << "\n"; cout << setw(26) << setprecision(16) << " XMAX = " << xmax << "\n"; return; } //****************************************************************************80 void r8_machar_test ( ) //****************************************************************************80 // // Purpose: // // R8_MACHAR_TEST tests R8_MACHAR. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 April 2007 // // Author: // // John Burkardt // { double eps; double epsneg; long int ibeta; long int iexp; long int irnd; long int it; long int machep; long int maxexp; long int minexp; long int negep; long int ngrd; double xmax; double xmin; cout << "\n"; cout << "R8_MACHAR_TEST\n"; cout << " R8_MACHAR computes double\n"; cout << " precision machine constants.\n"; r8_machar ( &ibeta, &it, &irnd, &ngrd, &machep, &negep, &iexp, &minexp, &maxexp, &eps, &epsneg, &xmin, &xmax ); cout << "\n"; cout << " IBETA = " << ibeta << "\n"; cout << " IT = " << it << "\n"; cout << " IRND = " << irnd << "\n"; cout << " NGRD = " << ngrd << "\n"; cout << " MACHEP = " << machep << "\n"; cout << " NEGEP = " << negep << "\n"; cout << " IEXP = " << iexp << "\n"; cout << " MINEXP = " << minexp << "\n"; cout << " MAXEXP = " << maxexp << "\n"; cout << setw(26) << setprecision(16) << " EPS = " << eps << "\n"; cout << setw(26) << setprecision(16) << " EPSNEG = " << epsneg << "\n"; cout << setw(26) << setprecision(16) << " XMIN = " << xmin << "\n"; cout << setw(26) << setprecision(16) << " XMAX = " << xmax << "\n"; return; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }