CppAD: A C++ Algorithmic Differentiation Package
20130102
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_INTEGER_INCLUDED 00003 # define CPPAD_INTEGER_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 /* 00017 ------------------------------------------------------------------------------ 00018 $begin Integer$$ 00019 $spell 00020 std 00021 VecAD 00022 CppAD 00023 namespace 00024 const 00025 bool 00026 $$ 00027 00028 $index Integer$$ 00029 00030 $index AD, convert to integer$$ 00031 $index convert, AD to integer$$ 00032 00033 $section Convert From AD to Integer$$ 00034 00035 $head Syntax$$ 00036 $icode%i% = Integer(%x%)%$$ 00037 00038 00039 $head Purpose$$ 00040 Converts from an AD type to the corresponding integer value. 00041 00042 $head i$$ 00043 The result $icode i$$ has prototype 00044 $codei% 00045 int %i% 00046 %$$ 00047 00048 $head x$$ 00049 00050 $subhead Real Types$$ 00051 If the argument $icode x$$ has either of the following prototypes: 00052 $codei% 00053 const float %% &%x% 00054 const double %% &%x% 00055 %$$ 00056 the fractional part is dropped to form the integer value. 00057 For example, if $icode x$$ is 1.5, $icode i$$ is 1. 00058 In general, if $latex x \geq 0$$, $icode i$$ is the 00059 greatest integer less than or equal $icode x$$. 00060 If $latex x \leq 0$$, $icode i$$ is the 00061 smallest integer greater than or equal $icode x$$. 00062 00063 $subhead Complex Types$$ 00064 If the argument $icode x$$ has either of the following prototypes: 00065 $codei% 00066 const std::complex<float> %% &%x% 00067 const std::complex<double> %% &%x% 00068 %$$ 00069 The result $icode i$$ is given by 00070 $codei% 00071 %i% = Integer(%x%.real()) 00072 %$$ 00073 00074 $subhead AD Types$$ 00075 If the argument $icode x$$ has either of the following prototypes: 00076 $codei% 00077 const AD<%Base%> &%x% 00078 const VecAD<%Base%>::reference &%x% 00079 %$$ 00080 $icode Base$$ must support the $code Integer$$ function and 00081 the conversion has the same meaning as for $icode Base$$. 00082 00083 $head Operation Sequence$$ 00084 The result of this operation is not an 00085 $cref/AD of Base/glossary/AD of Base/$$ object. 00086 Thus it will not be recorded as part of an 00087 AD of $icode Base$$ 00088 $cref/operation sequence/glossary/Operation/Sequence/$$. 00089 00090 $head Example$$ 00091 $children% 00092 example/integer.cpp 00093 %$$ 00094 The file 00095 $cref integer.cpp$$ 00096 contains an example and test of this operation. 00097 00098 $end 00099 ------------------------------------------------------------------------------ 00100 */ 00101 00102 00103 namespace CppAD { 00104 00105 template <class Base> 00106 CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION 00107 int Integer(const AD<Base> &x) 00108 { return Integer(x.value_); } 00109 00110 template <class Base> 00111 CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION 00112 int Integer(const VecAD_reference<Base> &x) 00113 { return Integer( x.ADBase() ); } 00114 } 00115 # endif 00116