00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00033
00034 #ifndef GROOVX_PKGS_WHITEBOX_NUMTEST_CC_UTC20050626084022_DEFINED
00035 #define GROOVX_PKGS_WHITEBOX_NUMTEST_CC_UTC20050626084022_DEFINED
00036
00037 #include "pkgs/whitebox/numtest.h"
00038
00039 #include "mtx/mathspecial.h"
00040
00041 #include "tcl/pkg.h"
00042
00043 #include "rutz/unittest.h"
00044
00045 #include "rutz/trace.h"
00046
00047 namespace
00048 {
00049 void testErfc()
00050 {
00051
00052 TEST_REQUIRE_APPROX(dash::erfc(0), ::erfc(0), 1e-5);
00053 TEST_REQUIRE_APPROX(dash::erfc(1), ::erfc(1), 1e-5);
00054 TEST_REQUIRE_APPROX(dash::erfc(-1), ::erfc(-1), 1e-5);
00055
00056
00057 TEST_REQUIRE_APPROX(dash::erfc(0), 1, 1e-5);
00058 TEST_REQUIRE_APPROX(dash::erfc(1), 0.1573, 1e-5);
00059 TEST_REQUIRE_APPROX(dash::erfc(-1), 1.8427, 1e-5);
00060
00061
00062
00063 TEST_REQUIRE_APPROX(dash::erfc(1), 2-dash::erfc(-1), 1e-5);
00064 TEST_REQUIRE_APPROX(dash::erfc(2), 2-dash::erfc(-2), 1e-5);
00065
00066
00067 static rutz::prof p1("testprof/erfc/custom", __FILE__, __LINE__);
00068 static rutz::prof p2("testprof/erfc/builtin", __FILE__, __LINE__);
00069
00070 {
00071 rutz::trace t(p1, false);
00072 double x = 0.0;
00073 for (int i = 0; i < 2500; ++i)
00074 for (int f = 1; f <= 100; ++f)
00075 x += dash::erfc(double(i)/1000.0);
00076 }
00077
00078 {
00079 rutz::trace t(p2, false);
00080 double x = 0.0;
00081 for (int i = 0; i < 2500; ++i)
00082 for (int f = 1; f <= 100; ++f)
00083 x += ::erfc(double(i)/1000.0);
00084 }
00085 }
00086
00087 void testGammaln()
00088 {
00089
00090 for (int f = 1; f <= 100; ++f)
00091 TEST_REQUIRE_APPROX(dash::gammaln(f), ::lgamma(f), 1e-5);
00092
00093 static rutz::prof p1("testprof/gammaln/custom", __FILE__, __LINE__);
00094 static rutz::prof p2("testprof/gammaln/builtin", __FILE__, __LINE__);
00095
00096 {
00097 rutz::trace t(p1, false);
00098 double x = 0.0;
00099 for (int i = 0; i < 2500; ++i)
00100 for (int f = 1; f <= 100; ++f)
00101 x += dash::gammaln(f);
00102 }
00103
00104 {
00105 rutz::trace t(p2, false);
00106 double x = 0.0;
00107 for (int i = 0; i < 2500; ++i)
00108 for (int f = 1; f <= 100; ++f)
00109 x += ::lgamma(f);
00110 }
00111 }
00112 }
00113
00114 extern "C"
00115 int Numtest_Init(Tcl_Interp* interp)
00116 {
00117 GVX_TRACE("Numtest_Init");
00118
00119 GVX_PKG_CREATE(pkg, interp, "Numtest", "4.$Revision: 10065 $");
00120
00121 DEF_TEST(pkg, testErfc);
00122 DEF_TEST(pkg, testGammaln);
00123
00124 GVX_PKG_RETURN(pkg);
00125 }
00126
00127
00128 extern "C" int Numtest_SafeInit(Tcl_Interp*) { return 1; }
00129
00130 extern "C" int Numtest_Unload(Tcl_Interp* interp, int )
00131 {
00132 GVX_TRACE("Numtest_Unload");
00133 return tcl::pkg::destroy_on_unload(interp, "Numtest");
00134 }
00135
00136 extern "C" int Numtest_SafeUnload(Tcl_Interp*, int ) { return 1; }
00137
00138 static const char __attribute__((used)) vcid_groovx_pkgs_whitebox_numtest_cc_utc20050626084022[] = "$Id: numtest.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00139 #endif // !GROOVX_PKGS_WHITEBOX_NUMTEST_CC_UTC20050626084022_DEFINED