# include # include # include # include # include "asa245.h" int main ( ); void test01 ( ); void test02 ( ); void test03 ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: asa245_test() tests asa245(). Licensing: This code is distributed under the MIT license. Modified: 25 September 2014 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "asa245_test():\n" ); printf ( " C version\n" ); printf ( " Test asa245().\n" ); test01 ( ); test02 ( ); test03 ( ); /* Terminate. */ printf ( "\n" ); printf ( "asa245_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void test01 ( ) /******************************************************************************/ /* Purpose: test01() tests alngam(). Licensing: This code is distributed under the MIT license. Modified: 20 November 2010 Author: John Burkardt */ { double fx; double fx2; int ifault; int n_data; double x; printf ( "\n" ); printf ( "test01():\n" ); printf ( " alngam() computes the logarithm of the \n" ); printf ( " Gamma function. We compare the result\n" ); printf ( " to tabulated values.\n" ); printf ( "\n" ); printf ( " X " ); printf ( "FX FX2\n" ); printf ( " " ); printf ( "(Tabulated) (ALNGAM) DIFF\n" ); printf ( "\n" ); n_data = 0; for ( ; ; ) { gamma_log_values ( &n_data, &x, &fx ); if ( n_data == 0 ) { break; } fx2 = alngam ( x, &ifault ); printf ( " %24.16f %24.16f %24.16f %10.4e\n", x, fx, fx2, fabs ( fx - fx2 ) ); } return; } /******************************************************************************/ void test02 ( ) /******************************************************************************/ /* Purpose: test02() tests lngamma(). Licensing: This code is distributed under the MIT license. Modified: 20 November 2010 Author: John Burkardt */ { double fx; double fx2; int ier; int n_data; double x; printf ( "\n" ); printf ( "test02():\n" ); printf ( " lngamma() computes the logarithm of the \n" ); printf ( " Gamma function. We compare the result\n" ); printf ( " to tabulated values.\n" ); printf ( "\n" ); printf ( " X " ); printf ( "FX FX2\n" ); printf ( " " ); printf ( "(Tabulated) (LNGAMMA) DIFF\n" ); printf ( "\n" ); n_data = 0; for ( ; ; ) { gamma_log_values ( &n_data, &x, &fx ); if ( n_data == 0 ) { break; } fx2 = lngamma ( x, &ier ); printf ( " %24.16f %24.16f %24.16f %10.4e\n", x, fx, fx2, fabs ( fx - fx2 ) ); } return; } /******************************************************************************/ void test03 ( ) /******************************************************************************/ /* Purpose: test03() tests lgamma(). Licensing: This code is distributed under the MIT license. Modified: 25 September 2014 Author: John Burkardt */ { double fx; double fx2; int n_data; double x; printf ( "\n" ); printf ( "test03():\n" ); printf ( " lgamma() computes the logarithm of the \n" ); printf ( " Gamma function.\n" ); printf ( " LGAMMA is available with the GCC compiler.\n" ); printf ( " We compare the result to tabulated values.\n" ); printf ( "\n" ); printf ( " X " ); printf ( "FX FX2\n" ); printf ( " " ); printf ( "(Tabulated) (LGAMMA) DIFF\n" ); printf ( "\n" ); n_data = 0; for ( ; ; ) { gamma_log_values ( &n_data, &x, &fx ); if ( n_data == 0 ) { break; } fx2 = lgamma ( x ); printf ( " %24.16f %24.16f %24.16f %10.4e\n", x, fx, fx2, fabs ( fx - fx2 ) ); } return; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 17 June 2014 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }