CppAD: A C++ Algorithmic Differentiation Package  20130102
div_eq.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_DIV_EQ_INCLUDED
00003 # define CPPAD_DIV_EQ_INCLUDED
00004 
00005 /* --------------------------------------------------------------------------
00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
00007 
00008 CppAD is distributed under multiple licenses. This distribution is under
00009 the terms of the 
00010                     Eclipse Public License Version 1.0.
00011 
00012 A copy of this license is included in the COPYING file of this distribution.
00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00014 -------------------------------------------------------------------------- */
00015 
00016 //  BEGIN CppAD namespace
00017 namespace CppAD {
00018 
00019 template <class Base>
00020 AD<Base>& AD<Base>::operator /= (const AD<Base> &right)
00021 {
00022      // compute the Base part
00023      Base left;
00024      left    = value_;
00025      value_ /= right.value_;
00026 
00027      // check if there is a recording in progress
00028      ADTape<Base>* tape = AD<Base>::tape_ptr();
00029      if( tape == CPPAD_NULL )
00030           return *this;
00031      tape_id_t tape_id = tape->id_;
00032 
00033      // tape_id cannot match the default value for tape_id_; i.e., 0
00034      CPPAD_ASSERT_UNKNOWN( tape_id > 0 );
00035      bool var_left  = tape_id_       == tape_id;
00036      bool var_right = right.tape_id_ == tape_id;
00037 
00038      if( var_left )
00039      {    if( var_right )
00040           {    // this = variable / variable
00041                CPPAD_ASSERT_UNKNOWN( NumRes(DivvvOp) == 1 );
00042                CPPAD_ASSERT_UNKNOWN( NumArg(DivvvOp) == 2 );
00043 
00044                // put operand addresses in tape
00045                tape->Rec_.PutArg(taddr_, right.taddr_);
00046                // put operator in the tape
00047                taddr_ = tape->Rec_.PutOp(DivvvOp);
00048                // make this a variable
00049                CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id );
00050           }
00051           else if( IdenticalOne( right.value_ ) )
00052           {    // this = variable * 1
00053           }
00054           else 
00055           {    // this = variable / parameter
00056                CPPAD_ASSERT_UNKNOWN( NumRes(DivvpOp) == 1 );
00057                CPPAD_ASSERT_UNKNOWN( NumArg(DivvpOp) == 2 );
00058 
00059                // put operand addresses in tape
00060                addr_t p = tape->Rec_.PutPar(right.value_);
00061                tape->Rec_.PutArg(taddr_, p);
00062                // put operator in the tape
00063                taddr_ = tape->Rec_.PutOp(DivvpOp);
00064                // make this a variable
00065                CPPAD_ASSERT_UNKNOWN( tape_id_ == tape_id );
00066           }
00067      }
00068      else if( var_right  )
00069      {    if( IdenticalZero(left) )
00070           {    // this = 0 / variable
00071           }
00072           else
00073           {    // this = parameter / variable
00074                CPPAD_ASSERT_UNKNOWN( NumRes(DivpvOp) == 1 );
00075                CPPAD_ASSERT_UNKNOWN( NumArg(DivpvOp) == 2 );
00076 
00077                // put operand addresses in tape
00078                addr_t p = tape->Rec_.PutPar(left);
00079                tape->Rec_.PutArg(p, right.taddr_);
00080                // put operator in the tape
00081                taddr_ = tape->Rec_.PutOp(DivpvOp);
00082                // make this a variable
00083                tape_id_ = tape_id;
00084           }
00085      }
00086      return *this;
00087 }
00088 
00089 CPPAD_FOLD_ASSIGNMENT_OPERATOR(/=)
00090 
00091 } // END CppAD namespace
00092 
00093 # endif 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines