$Id: numeric_type.omh 2506 2012-10-24 19:36:49Z bradbell $ /* -------------------------------------------------------------------------- CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell CppAD is distributed under multiple licenses. This distribution is under the terms of the Eclipse Public License Version 1.0. A copy of this license is included in the COPYING file of this distribution. Please visit http://www.coin-or.org/CppAD/ for information on other licenses. -------------------------------------------------------------------------- */ /* $begin NumericType$$ $spell const std valarray $$ $index numeric, type$$ $index type, numeric$$ $section Definition of a Numeric Type$$ $head Type Requirements$$ A $icode NumericType$$ is any type that satisfies the requirements below. The following is a list of some numeric types: $code int$$, $code float$$, $code double$$, $code AD$$, $code AD< AD >$$. The routine $cref CheckNumericType$$ can be used to check that a type satisfies these conditions. $head Default Constructor$$ $index default, numeric constructor$$ $index constructor, numeric$$ The syntax $codei% %NumericType% %x%; %$$ creates a $icode NumericType$$ object with an unspecified value. $head Constructor From Integer$$ $index int, numeric constructor$$ $index constructor, numeric$$ If $icode i$$ is an $code int$$, the syntax $codei% %NumericType% %x%(%i%); %$$ creates a $icode NumericType$$ object with a value equal to $icode i$$ where $icode i$$ can be $code const$$. $head Copy Constructor$$ $index copy, numeric constructor$$ $index constructor, numeric copy$$ If $icode x$$ is a $icode NumericType$$ object the syntax $codei% %NumericType% %y%(%x%); %$$ creates a $icode NumericType$$ object $icode y$$ with the same value as $icode x$$ where $icode x$$ can be $code const$$. $head Assignment$$ If $icode x$$ and $icode y$$ are $icode NumericType$$ objects, the syntax $codei% %x% = %y% %$$ sets the value of $icode x$$ equal to the value of $icode y$$ where $icode y$$ can be $code const$$. The expression corresponding to this operation is unspecified; i.e., it could be $code void$$ and hence $codei% %x% = %y% = %z% %$$ may not be legal. $head Operators$$ Suppose $icode x$$, $icode y$$ and $icode z$$ $icode NumericType$$ objects where $icode x$$ and $icode y$$ may be $code const$$. In the result type column, $icode NumericType$$ can be replaced by any type that can be used just like a $icode NumericType$$ object. $table $bold Operation$$ $cnext $bold Description$$ $cnext $bold Result Type$$ $rnext $codei%+%x%$$ $cnext unary plus $cnext $icode NumericType$$ $rnext $codei%-%x%$$ $cnext unary minus $cnext $icode NumericType$$ $rnext $icode%x% + %y%$$ $cnext binary addition $cnext $icode NumericType$$ $rnext $icode%x% - %y%$$ $cnext binary subtraction $cnext $icode NumericType$$ $rnext $icode%x% * %y%$$ $cnext binary multiplication $cnext $icode NumericType$$ $rnext $icode%x% / %y%$$ $cnext binary division $cnext $icode NumericType$$ $rnext $icode%z% += %y%$$ $cnext computed assignment addition $cnext unspecified $rnext $icode%z% -= %y%$$ $cnext computed assignment subtraction $cnext unspecified $rnext $icode%z% *= %y%$$ $cnext computed assignment multiplication $cnext unspecified $rnext $icode%z% /= %y%$$ $cnext computed assignment division $cnext unspecified $tend $head Example$$ $children% example/numeric_type.cpp %$$ The file $cref numeric_type.cpp$$ contains an example and test of using numeric types. It returns true if it succeeds and false otherwise. (It is easy to modify to test additional numeric types.) $head Exercise$$ $index exercise, numeric type$$ $list number$$ List three operators that are not supported by every numeric type but that are supported by the numeric types $code int$$, $code float$$, $code double$$. $lnext Which of the following are numeric types: $code std::complex$$, $code std::valarray$$, $code std::vector$$ ? $lend $end