lines 125-216 of file: example/class.cpp {xrst_begin example_ad_double} {xrst_spell ay dx dy ok } An Example Using the ad_double Class #################################### This example mixes the documentation and the example code. Another choice is to put the documentation and the beginning an then just have comments in the code. xrst_indent *********** This example make uses of ``xrst_indent`` so that the xrst input can be indented at the same level as the code it is next to. Begin Function ************** This function has no arguments and returns a boolean that is true, if all it's tests pass, and false otherwise. {xrst_code cpp} */ bool test_ad_double(void) { /* {xrst_code} {xrst_indent} Initialize ok ************* {xrst_code cpp} */ bool ok = true; /* {xrst_code} Independent Variable ******************** {xrst_code cpp} */ double x = 2.0; double dx = 3.0; ad_double ax(x, dx); /* {xrst_code} Addition ******** {xrst_code cpp} */ { ad_double ay = ax + ax; double dy = ay.derivative(); ok &= dy == 2.0 * dx; } /* {xrst_code} Subtraction *********** {xrst_code cpp} */ { ad_double ay = ax - ax; double dy = ay.derivative(); ok &= dy == 0.0; } /* {xrst_code} Multiplication ************** {xrst_code cpp} */ { ad_double ay = ax * ax; double dy = ay.derivative(); ok &= dy == 2.0 * x * dx; } /* {xrst_code} Division ******** {xrst_code cpp} */ { ad_double ay = ax / ax; double dy = ay.derivative(); ok &= dy == 0.0; } /* {xrst_code} Return ok ********* {xrst_indent} {xrst_code cpp} */ return ok; } /* {xrst_code} Example File ************ :ref:`class_example@This Example File` is the same as for the parent of this page. {xrst_end example_ad_double}