Prev Next numeric_type.cpp Headings

@(@\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@ This is cppad-20221105 documentation. Here is a link to its current documentation .
The NumericType: Example and Test

# include <cppad/cppad.hpp>

namespace { // Empty namespace

    // -------------------------------------------------------------------
    class MyType {
    private:
        double d;
    public:
        // constructor from void
        MyType(void) : d(0.)
        { }
        // constructor from an int
        MyType(int d_) : d(d_)
        { }
        // copy constructor
        MyType(const MyType &x)
        {   d = x.d; }
        // assignment operator
        void operator = (const MyType &x)
        {   d = x.d; }
        // member function that converts to double
        double Double(void) const
        {   return d; }
        // unary plus
        MyType operator + (void) const
        {   MyType x;
            x.d =  d;
            return x;
        }
        // unary plus
        MyType operator - (void) const
        {   MyType x;
            x.d = - d;
            return x;
        }
        // binary addition
        MyType operator + (const MyType &x) const
        {   MyType y;
            y.d = d + x.d ;
            return y;
        }
        // binary subtraction
        MyType operator - (const MyType &x) const
        {   MyType y;
            y.d = d - x.d ;
            return y;
        }
        // binary multiplication
        MyType operator * (const MyType &x) const
        {   MyType y;
            y.d = d * x.d ;
            return y;
        }
        // binary division
        MyType operator / (const MyType &x) const
        {   MyType y;
            y.d = d / x.d ;
            return y;
        }
        // compound assignment addition
        void operator += (const MyType &x)
        {   d += x.d; }
        // compound assignment subtraction
        void operator -= (const MyType &x)
        {   d -= x.d; }
        // compound assignment multiplication
        void operator *= (const MyType &x)
        {   d *= x.d; }
        // compound assignment division
        void operator /= (const MyType &x)
        {   d /= x.d; }
    };
}
bool NumericType(void)
{   bool ok  = true;
    using CppAD::AD;
    using CppAD::CheckNumericType;

    CheckNumericType<MyType>            ();

    CheckNumericType<int>               ();
    CheckNumericType<double>            ();
    CheckNumericType< AD<double> >      ();
    CheckNumericType< AD< AD<double> > >();

    return ok;
}

Input File: example/general/numeric_type.cpp