00001 # ifndef CPPAD_COMPARE_INCLUDED
00002 # define CPPAD_COMPARE_INCLUDED
00003
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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 namespace CppAD {
00134
00135 template <class Base>
00136
00137
00138 void ADTape<Base>::RecordCompare(
00139 enum CompareOp cop ,
00140 bool result ,
00141 const AD<Base> &left ,
00142 const AD<Base> &right )
00143 { size_t ind0, ind1, ind2, ind3;
00144
00145
00146 ind1 = 0;
00147
00148
00149 if( Parameter(left) )
00150 ind2 = Rec.PutPar(left.value_);
00151 else
00152 { ind1 += 2;
00153 ind2 = left.taddr_;
00154 }
00155
00156
00157 if( Parameter(right) )
00158 ind3 = Rec.PutPar(right.value_);
00159 else
00160 { ind1 += 4;
00161 ind3 = right.taddr_;
00162 }
00163
00164
00165 if( ind1 == 0 )
00166 return;
00167
00168
00169 if( result )
00170 ind1+= 1;
00171
00172
00173 ind0 = size_t (cop);
00174
00175 CPPAD_ASSERT_UNKNOWN( ind1 > 1 );
00176 CPPAD_ASSERT_UNKNOWN( NumInd(ComOp) == 4 );
00177
00178
00179 Rec.PutOp(ComOp);
00180 Rec.PutInd(ind0, ind1, ind2, ind3);
00181 }
00182
00183
00184 # ifdef NDEBUG
00185
00186 template <class Base>
00187 inline bool AD<Base>::operator < (const AD<Base> &right) const
00188 { bool result = (value_ < right.value_);
00189 return result;
00190 }
00191
00192 # else
00193 template <class Base>
00194 inline bool AD<Base>::operator < (const AD<Base> &right) const
00195 { bool result = (value_ < right.value_);
00196
00197 ADTape<Base> *tape = CPPAD_NULL;
00198 if( Variable(*this) )
00199 tape = tape_this();
00200 else if ( Variable(right) )
00201 tape = right.tape_this();
00202
00203 if( tape != CPPAD_NULL )
00204 tape->RecordCompare(CompareLt, result, *this, right);
00205
00206 return result;
00207 }
00208 # endif
00209
00210
00211 CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(<)
00212
00213
00214 # ifdef NDEBUG
00215
00216 template <class Base>
00217 inline bool AD<Base>::operator <= (const AD<Base> &right) const
00218 { bool result = (value_ <= right.value_);
00219 return result;
00220 }
00221
00222 # else
00223 template <class Base>
00224 inline bool AD<Base>::operator <= (const AD<Base> &right) const
00225 { bool result = (value_ <= right.value_);
00226
00227 ADTape<Base> *tape = CPPAD_NULL;
00228 if( Variable(*this) )
00229 tape = tape_this();
00230 else if ( Variable(right) )
00231 tape = right.tape_this();
00232
00233 if( tape != CPPAD_NULL )
00234 tape->RecordCompare(CompareLe, result, *this, right);
00235
00236 return result;
00237 }
00238 # endif
00239
00240
00241 CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(<=)
00242
00243
00244
00245 # ifdef NDEBUG
00246
00247 template <class Base>
00248 inline bool AD<Base>::operator > (const AD<Base> &right) const
00249 { bool result = (value_ > right.value_);
00250 return result;
00251 }
00252
00253 # else
00254 template <class Base>
00255 inline bool AD<Base>::operator > (const AD<Base> &right) const
00256 { bool result = (value_ > right.value_);
00257
00258 ADTape<Base> *tape = CPPAD_NULL;
00259 if( Variable(*this) )
00260 tape = tape_this();
00261 else if ( Variable(right) )
00262 tape = right.tape_this();
00263
00264 if( tape != CPPAD_NULL )
00265 tape->RecordCompare(CompareGt, result, *this, right);
00266
00267
00268 return result;
00269 }
00270 # endif
00271
00272
00273 CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(>)
00274
00275
00276 # ifdef NDEBUG
00277
00278 template <class Base>
00279 inline bool AD<Base>::operator >= (const AD<Base> &right) const
00280 { bool result = (value_ >= right.value_);
00281 return result;
00282 }
00283
00284 # else
00285 template <class Base>
00286 inline bool AD<Base>::operator >= (const AD<Base> &right) const
00287 { bool result = (value_ >= right.value_);
00288
00289 ADTape<Base> *tape = CPPAD_NULL;
00290 if( Variable(*this) )
00291 tape = tape_this();
00292 else if ( Variable(right) )
00293 tape = right.tape_this();
00294
00295 if( tape != CPPAD_NULL )
00296 tape->RecordCompare(CompareGe, result, *this, right);
00297
00298 return result;
00299 }
00300 # endif
00301
00302
00303 CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(>=)
00304
00305
00306
00307 # ifdef NDEBUG
00308
00309 template <class Base>
00310 inline bool AD<Base>::operator == (const AD<Base> &right) const
00311 { bool result = (value_ == right.value_);
00312 return result;
00313 }
00314
00315 # else
00316 template <class Base>
00317 inline bool AD<Base>::operator == (const AD<Base> &right) const
00318 { bool result = (value_ == right.value_);
00319
00320 ADTape<Base> *tape = CPPAD_NULL;
00321 if( Variable(*this) )
00322 tape = tape_this();
00323 else if ( Variable(right) )
00324 tape = right.tape_this();
00325
00326 if( tape != CPPAD_NULL )
00327 tape->RecordCompare(CompareEq, result, *this, right);
00328
00329 return result;
00330 }
00331 # endif
00332
00333
00334 CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(==)
00335
00336
00337 # ifdef NDEBUG
00338
00339 template <class Base>
00340 inline bool AD<Base>::operator != (const AD<Base> &right) const
00341 { bool result = (value_ != right.value_);
00342 return result;
00343 }
00344
00345 # else
00346 template <class Base>
00347 inline bool AD<Base>::operator != (const AD<Base> &right) const
00348 { bool result = (value_ != right.value_);
00349
00350 ADTape<Base> *tape = CPPAD_NULL;
00351 if( Variable(*this) )
00352 tape = tape_this();
00353 else if ( Variable(right) )
00354 tape = right.tape_this();
00355
00356 if( tape != CPPAD_NULL )
00357 tape->RecordCompare(CompareNe, result, *this, right);
00358
00359 return result;
00360 }
00361 # endif
00362
00363
00364 CPPAD_FOLD_BOOL_VALUED_BINARY_OPERATOR(!=)
00365
00366 }
00367
00368 # endif