diff --git a/include/cppad/core/base_complex.hpp b/include/cppad/core/base_complex.hpp index 082c48609..9acad46ef 100644 --- a/include/cppad/core/base_complex.hpp +++ b/include/cppad/core/base_complex.hpp @@ -2,7 +2,7 @@ # define CPPAD_CORE_BASE_COMPLEX_HPP // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later // SPDX-FileCopyrightText: Bradley M. Bell -// SPDX-FileContributor: 2003-23 Bradley M. Bell +// SPDX-FileContributor: 2003-24 Bradley M. Bell // ---------------------------------------------------------------------------- # include # include @@ -12,7 +12,7 @@ {xrst_begin base_complex.hpp} {xrst_spell complier - invocations + ge isnan } @@ -44,13 +44,28 @@ in addition to including CondExpOp ********* -The type ``std::complex`` does not supports the -``<`` , ``<=`` , ``==`` , ``>=`` , and ``>`` operators; see +The type ``std::complex`` does not support the +``<`` , ``<=`` , ``>=`` , and ``>`` operators; see :ref:`base_cond_exp@CondExpTemplate@Not Ordered` . -Hence its ``CondExpOp`` function is defined by +Hence these operators and ``CondExpOp`` function are defined by {xrst_spell_off} {xrst_code cpp} */ +# define CPPAD_TEMP(op) \ + inline bool operator op( \ + const std::complex& left , \ + const std::complex& right ) \ + { CppAD::ErrorHandler::Call( \ + true , __LINE__ , __FILE__ , \ + "std::complex " #op " std::complex" , \ + "Error: std::complex is not an ordered type" \ + ); \ + return false; \ + } namespace CppAD { + CPPAD_TEMP(<) + CPPAD_TEMP(<=) + CPPAD_TEMP(>=) + CPPAD_TEMP(>) inline std::complex CondExpOp( enum CppAD::CompareOp cop , const std::complex &left , @@ -65,9 +80,11 @@ namespace CppAD { return std::complex(0); } } +# undef CPPAD_TEMP /* {xrst_code} {xrst_spell_on} + CondExpRel ********** The :ref:`CPPAD_COND_EXP_REL` macro invocation diff --git a/test_more/general/CMakeLists.txt b/test_more/general/CMakeLists.txt index f00b4d6ce..3484afa87 100644 --- a/test_more/general/CMakeLists.txt +++ b/test_more/general/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later # SPDX-FileCopyrightText: Bradley M. Bell -# SPDX-FileContributor: 2003-23 Bradley M. Bell +# SPDX-FileContributor: 2003-24 Bradley M. Bell # ---------------------------------------------------------------------------- # Build the test_more/general tests # @@ -48,6 +48,7 @@ SET(source_list azmul.cpp base2ad.cpp base_alloc.cpp + base_complex.cpp bool_sparsity.cpp check_simple_vector.cpp chkpoint_one.cpp diff --git a/test_more/general/base_complex.cpp b/test_more/general/base_complex.cpp new file mode 100644 index 000000000..d7787cc18 --- /dev/null +++ b/test_more/general/base_complex.cpp @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later +// SPDX-FileCopyrightText: Bradley M. Bell +// SPDX-FileContributor: 2003-24 Bradley M. Bell +// ---------------------------------------------------------------------------- + +#include + +bool base_complex(void) +{ // ok + bool ok = true; + // + // base, ad_base + typedef std::complex base; + typedef CppAD::AD ad_base; + // + // f + CPPAD_TESTVECTOR(ad_base) ax(1), ay(1); + ax[0] = 0.0; + CppAD::Independent(ax); + ay[0] = ax[0] * ax[0]; + CppAD::ADFun f(ax, ay); + // + // f + f.optimize(); + // + // dy + std::vector x(1), dx(1), dy(1); + x[0] = 5; + f.Forward(0, x); + dx[0] = 1; + dy = f.Forward(1, dx); + // + // ok + ok &= dy[0] == 2.0 * x[0]; + // + return ok; +} diff --git a/test_more/general/general.cpp b/test_more/general/general.cpp index 4b9a6c78b..690db99b3 100644 --- a/test_more/general/general.cpp +++ b/test_more/general/general.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later // SPDX-FileCopyrightText: Bradley M. Bell -// SPDX-FileContributor: 2003-22 Bradley M. Bell +// SPDX-FileContributor: 2003-24 Bradley M. Bell // ---------------------------------------------------------------------------- // CPPAD_HAS_* defines @@ -71,6 +71,7 @@ extern bool azmul(void); extern bool base2ad(void); extern bool base_adolc(void); extern bool base_alloc_test(void); +extern bool base_complex(void); extern bool bool_sparsity(void); extern bool check_simple_vector(void); extern bool chkpoint_one(void); @@ -193,6 +194,7 @@ int main(void) Run( atomic_three, "atomic_three" ); Run( azmul, "azmul" ); Run( base2ad, "base2ad" ); + Run( base_complex, "base_complex" ); Run( bool_sparsity, "bool_sparsity" ); Run( check_simple_vector, "check_simple_vector" ); Run( chkpoint_one, "chkpoint_one" );