Sacado Package Browser (Single Doxygen Collection) Version of the Day
tradoptest_45.cpp
Go to the documentation of this file.
00001 
00002 
00003 /* Try to test all combinations of types and operations */
00004 
00005 
00006 
00007 #define ADT_RAD Sacado::Rad::
00008 
00009 
00010 
00011 #include "Sacado_trad.hpp"
00012 #ifdef _MSC_VER
00013 #include "winmath.h"
00014 #endif
00015 #include <cstdio>
00016 
00017 using std::printf;
00018 
00019 
00020 
00021 typedef ADT_RAD IndepADvar<double> AI;
00022 
00023 typedef ADT_RAD ADvar<double> A;
00024 
00025 typedef ADT_RAD ConstADvar<double> C;
00026 
00027 typedef ADT_RAD ADvari<double> Ai;
00028 
00029 typedef const ADT_RAD IndepADvar<double> cAI;
00030 
00031 typedef const ADT_RAD ADvar<double> cA;
00032 
00033 typedef const ADT_RAD ConstADvar<double> cC;
00034 
00035 typedef const ADT_RAD ADvari<double> cAi;
00036 
00037 static int rc;
00038 
00039 
00040 
00041 /* This is to be run through an awk program that changes lines */
00042 
00043 /* with "BINTEST" or "UNOPTEST" at the beginning of the line into */
00044 
00045 /* a the desired C++ (which we can then inspect). */
00046 
00047 
00048 
00049  void
00050 
00051 botch(const char *what, double wanted, double got)
00052 
00053 {
00054 
00055   printf("%s: expected %g, got %g, diff = %.2g\n", what, wanted, got, wanted-got);
00056 
00057   rc = 1;
00058 
00059   }
00060 
00061 
00062 
00063  const double tol = 5e-16;
00064 
00065 
00066 
00067  int
00068 
00069 differ(double a, double b)
00070 
00071 {
00072 
00073   double d = a - b;
00074 
00075   if (d < 0.)
00076 
00077     d = -d;
00078 
00079   if (a < 0.)
00080 
00081     a = -a;
00082 
00083   if (b < 0.)
00084 
00085     b = -b;
00086 
00087   if (a < b)
00088 
00089     a = b;
00090 
00091   if (a > 0.)
00092 
00093     d /= a;
00094 
00095   return d > tol;
00096 
00097   }
00098 
00099 
00100 
00101 #ifndef RAD_EQ_ALIAS
00102 
00103 #define Plus_dx 1.
00104 
00105 #else
00106 
00107 #ifdef RAD_AUTO_AD_Const
00108 
00109 #define Plus_dx 1.
00110 
00111 #else
00112 
00113 #define Plus_dx 0.
00114 
00115 #endif
00116 
00117 #endif
00118 
00119 
00120 
00121  int
00122 
00123 main(void)
00124 
00125 {
00126 
00127   AI xAI, yAI;
00128 
00129   A fA, xA, yA;
00130 
00131   C xC, yC;
00132 
00133   double dx, dy, f, xd, yd;
00134 
00135   long xL, yL;
00136 
00137   int xi, yi;
00138 
00139 
00140 
00141   rc = 0;
00142 
00143 
00144   /**** Test of asinh ****/
00145 
00146   xd = -2.; f = asinh(-2.); dx = 0.4472135954999579;
00147   xAI = xd;
00148   fA = asinh(xAI);
00149   A::Gradcomp();
00150   if (differ(fA.val(), f)) botch("fA = asinh(xAI)", f, fA.val());
00151   else if (differ(xAI.adj(), dx)) botch("d asinh(xAI)/dx", dx, xAI.adj());
00152   {
00153   A::aval_reset();
00154   cAI xcAI(xd);
00155   fA = asinh(xcAI);
00156   A::Gradcomp();
00157   if (differ(fA.val(), f)) botch("fA = asinh(xcAI)", f, fA.val());
00158   else if (differ(xcAI.adj(), dx)) botch("d asinh(xcAI)/dx", dx, xcAI.adj());
00159   }
00160   xA = xd;
00161   fA = asinh(xA);
00162   A::Gradcomp();
00163   if (differ(fA.val(), f)) botch("fA = asinh(xA)", f, fA.val());
00164   else if (differ(xA.adj(), dx)) botch("d asinh(xA)/dx", dx, xA.adj());
00165   {
00166   A::aval_reset();
00167   cA xcA(xd);
00168   fA = asinh(xcA);
00169   A::Gradcomp();
00170   if (differ(fA.val(), f)) botch("fA = asinh(xcA)", f, fA.val());
00171   else if (differ(xcA.adj(), dx)) botch("d asinh(xcA)/dx", dx, xcA.adj());
00172   }
00173   xC = xd;
00174   fA = asinh(xC);
00175   A::Gradcomp();
00176   if (differ(fA.val(), f)) botch("fA = asinh(xC)", f, fA.val());
00177   else if (differ(xC.adj(), dx)) botch("d asinh(xC)/dx", dx, xC.adj());
00178   {
00179   A::aval_reset();
00180   cC xcC(xd);
00181   fA = asinh(xcC);
00182   A::Gradcomp();
00183   if (differ(fA.val(), f)) botch("fA = asinh(xcC)", f, fA.val());
00184   else if (differ(xcC.adj(), dx)) botch("d asinh(xcC)/dx", dx, xcC.adj());
00185   }
00186   {
00187   cAi xcAi(xd);
00188   fA = asinh(xcAi);
00189   A::Gradcomp();
00190   if (differ(fA.val(), f)) botch("fA = asinh(xcAi)", f, fA.val());
00191   else if (differ(xcAi.aval, dx)) botch("d asinh(xcAi)/dx", dx, xcAi.aval);
00192   }
00193   {
00194   A::aval_reset();
00195   cAi xcAi(xd);
00196   fA = asinh(xcAi);
00197   A::Gradcomp();
00198   if (differ(fA.val(), f)) botch("fA = asinh(xcAi)", f, fA.val());
00199   else if (differ(xcAi.aval, dx)) botch("d asinh(xcAi)/dx", dx, xcAi.aval);
00200   }
00201 
00202 
00203   if (!rc) // chatter for cppunit test, which cannot tolerate silence
00204 
00205     printf("OK\n");
00206 
00207   return rc;
00208 
00209   }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines