From ff01a850fd159c7d8ee053120dd96a98ec753f47 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Mon, 9 Sep 2024 11:15:54 -0700 Subject: [PATCH] master: fix isnan ambibuity on Visual C++ 2022. --- appendix/whats_new/2024.xrst | 5 +- include/cppad/core/graph/from_graph.hpp | 64 +++++++++---------- include/cppad/core/graph/to_graph.hpp | 4 +- include/cppad/example/cppad_eigen.hpp | 4 +- .../cppad/local/optimize/get_par_usage.hpp | 4 +- include/cppad/local/optimize/optimize_run.hpp | 4 +- include/cppad/local/record/put_dyn_atomic.hpp | 4 +- include/cppad/local/record/recorder.hpp | 4 +- include/cppad/local/val_graph/val2fun.hpp | 8 +-- include/cppad/utility/nan.hpp | 12 +++- 10 files changed, 61 insertions(+), 52 deletions(-) diff --git a/appendix/whats_new/2024.xrst b/appendix/whats_new/2024.xrst index b757812a1..41604b1d0 100644 --- a/appendix/whats_new/2024.xrst +++ b/appendix/whats_new/2024.xrst @@ -13,6 +13,7 @@ dll env iostream + isnan nul nx omhelp @@ -32,7 +33,9 @@ mm-dd 09-09 ===== -The :ref:`cmake@CMake Command@Visual Studio` instructions were improved. +#. The :ref:`cmake@CMake Command@Visual Studio` instructions were improved. +#. ``CppAD`` was added before ``isnan`` , see the discussion of + :ref:`nan@std::isnan` . 08-10 ===== diff --git a/include/cppad/core/graph/from_graph.hpp b/include/cppad/core/graph/from_graph.hpp index c9e393032..0d983a208 100644 --- a/include/cppad/core/graph/from_graph.hpp +++ b/include/cppad/core/graph/from_graph.hpp @@ -2,7 +2,7 @@ # define CPPAD_CORE_GRAPH_FROM_GRAPH_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 @@ -268,7 +268,7 @@ void CppAD::ADFun::from_graph( CPPAD_ASSERT_UNKNOWN( parameter.size() == 0 ); addr_t i_par = rec.put_con_par(nan); CPPAD_ASSERT_UNKNOWN( i_par == 0 ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_par] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_par] ) ); // // Place the variable with index 0 in the tape CPPAD_ASSERT_NARG_NRES(local::BeginOp, 1, 1); @@ -286,7 +286,7 @@ void CppAD::ADFun::from_graph( } else { i_par = rec.put_dyn_par(nan, local::ind_dyn ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_par] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_par] ) ); node_type.push_back(dynamic_enum); node2fun.push_back(i_par); } @@ -297,7 +297,7 @@ void CppAD::ADFun::from_graph( for(size_t i = 0; i < n_variable_ind; ++i) { if( var2dyn[i] ) { i_par = rec.put_dyn_par(nan, local::ind_dyn ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_par] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_par] ) ); node_type.push_back(dynamic_enum); node2fun.push_back(i_par); } @@ -530,7 +530,7 @@ void CppAD::ADFun::from_graph( { i_result = rec.put_dyn_par( nan, local::add_dyn, i_result, temporary[j] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); } } else @@ -975,112 +975,112 @@ void CppAD::ADFun::from_graph( { case abs_graph_op: i_result = rec.put_dyn_par(nan, local::abs_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case acosh_graph_op: i_result = rec.put_dyn_par(nan, local::acosh_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case asinh_graph_op: i_result = rec.put_dyn_par(nan, local::asinh_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case atanh_graph_op: i_result = rec.put_dyn_par(nan, local::atanh_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case erf_graph_op: i_result = rec.put_dyn_par(nan, local::erf_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case erfc_graph_op: i_result = rec.put_dyn_par(nan, local::erfc_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case expm1_graph_op: i_result = rec.put_dyn_par(nan, local::expm1_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case log1p_graph_op: i_result = rec.put_dyn_par(nan, local::log1p_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case acos_graph_op: i_result = rec.put_dyn_par(nan, local::acos_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case asin_graph_op: i_result = rec.put_dyn_par(nan, local::asin_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case atan_graph_op: i_result = rec.put_dyn_par(nan, local::atan_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case cosh_graph_op: i_result = rec.put_dyn_par(nan, local::cosh_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case cos_graph_op: i_result = rec.put_dyn_par(nan, local::cos_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case exp_graph_op: i_result = rec.put_dyn_par(nan, local::exp_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case log_graph_op: i_result = rec.put_dyn_par(nan, local::log_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case neg_graph_op: i_result = rec.put_dyn_par(nan, local::neg_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case sign_graph_op: i_result = rec.put_dyn_par(nan, local::sign_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case sinh_graph_op: i_result = rec.put_dyn_par(nan, local::sinh_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case sin_graph_op: i_result = rec.put_dyn_par(nan, local::sin_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case sqrt_graph_op: i_result = rec.put_dyn_par(nan, local::sqrt_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case tanh_graph_op: i_result = rec.put_dyn_par(nan, local::tanh_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case tan_graph_op: i_result = rec.put_dyn_par(nan, local::tan_dyn, arg[0] ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; default: @@ -1367,19 +1367,19 @@ void CppAD::ADFun::from_graph( case add_graph_op: i_result = rec.put_dyn_par(nan, local::add_dyn, arg[0], arg[1]); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case azmul_graph_op: i_result = rec.put_dyn_par(nan, local::zmul_dyn, arg[0], arg[1]); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case div_graph_op: i_result = rec.put_dyn_par(nan, local::div_dyn, arg[0], arg[1]); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case mul_graph_op: @@ -1390,13 +1390,13 @@ void CppAD::ADFun::from_graph( case pow_graph_op: i_result = rec.put_dyn_par(nan, local::pow_dyn, arg[0], arg[1]); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; case sub_graph_op: i_result = rec.put_dyn_par(nan, local::sub_dyn, arg[0], arg[1]); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[i_result] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[i_result] ) ); break; default: diff --git a/include/cppad/core/graph/to_graph.hpp b/include/cppad/core/graph/to_graph.hpp index 8a238b51c..c45520666 100644 --- a/include/cppad/core/graph/to_graph.hpp +++ b/include/cppad/core/graph/to_graph.hpp @@ -3,7 +3,7 @@ // 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 @@ -113,7 +113,7 @@ void CppAD::ADFun::to_graph( CPPAD_ASSERT_UNKNOWN( n_dynamic_ind <= n_dynamic ); CPPAD_ASSERT_UNKNOWN( dyn_par_is.size() == n_parameter ); CPPAD_ASSERT_UNKNOWN( n_parameter > 0 ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[0] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[0] ) ); CPPAD_ASSERT_UNKNOWN( ! dyn_par_is[0] ); // -------------------------------------------------------------------- // par2node diff --git a/include/cppad/example/cppad_eigen.hpp b/include/cppad/example/cppad_eigen.hpp index ce7ee0479..e3d951984 100644 --- a/include/cppad/example/cppad_eigen.hpp +++ b/include/cppad/example/cppad_eigen.hpp @@ -2,7 +2,7 @@ # define CPPAD_EXAMPLE_CPPAD_EIGEN_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 // ---------------------------------------------------------------------------- /* @@ -244,7 +244,7 @@ namespace std { { return isfinite(CppAD::Value( CppAD::Var2Par(x) ) ); } template bool isnan(const CppAD::AD &x) - { return isnan(CppAD::Value( CppAD::Var2Par(x) ) ); } + { return CppAD::isnan(CppAD::Value( CppAD::Var2Par(x) ) ); } } /* {xrst_code} {xrst_spell_on} diff --git a/include/cppad/local/optimize/get_par_usage.hpp b/include/cppad/local/optimize/get_par_usage.hpp index 6968456d8..c8675dad3 100644 --- a/include/cppad/local/optimize/get_par_usage.hpp +++ b/include/cppad/local/optimize/get_par_usage.hpp @@ -2,7 +2,7 @@ # define CPPAD_LOCAL_OPTIMIZE_GET_PAR_USAGE_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 // ---------------------------------------------------------------------------- /*! \file get_cexp_info.hpp @@ -438,7 +438,7 @@ void get_par_usage( type_x.resize(n); for(size_t j = 0; j < n; ++j) { // parameter index zero is used for variable - CPPAD_ASSERT_UNKNOWN( isnan( all_par_vec[0] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( all_par_vec[0] ) ); addr_t arg_j = dyn_par_arg[i_arg + 5 + j]; parameter_x[j] = all_par_vec[arg_j]; if( arg_j == 0 ) diff --git a/include/cppad/local/optimize/optimize_run.hpp b/include/cppad/local/optimize/optimize_run.hpp index 546ad67f6..ca8e074ff 100644 --- a/include/cppad/local/optimize/optimize_run.hpp +++ b/include/cppad/local/optimize/optimize_run.hpp @@ -2,7 +2,7 @@ # define CPPAD_LOCAL_OPTIMIZE_OPTIMIZE_RUN_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 @@ -329,7 +329,7 @@ bool optimize_run( rec->set_record_compare( compare_op ); // copy parameters with index 0 - CPPAD_ASSERT_UNKNOWN( ! dyn_par_is[0] && isnan( play->GetPar(0) ) ); + CPPAD_ASSERT_UNKNOWN( ! dyn_par_is[0] && CppAD::isnan( play->GetPar(0) ) ); rec->put_con_par( play->GetPar(0) ); new_par[0] = 0; diff --git a/include/cppad/local/record/put_dyn_atomic.hpp b/include/cppad/local/record/put_dyn_atomic.hpp index c0e3f75fc..6e56f5f55 100644 --- a/include/cppad/local/record/put_dyn_atomic.hpp +++ b/include/cppad/local/record/put_dyn_atomic.hpp @@ -2,7 +2,7 @@ # define CPPAD_LOCAL_RECORD_PUT_DYN_ATOMIC_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 @@ -133,7 +133,7 @@ void recorder::put_dyn_atomic( case variable_enum: arg = 0; // phantom parameter index - CPPAD_ASSERT_UNKNOWN( isnan( all_par_vec_[arg] ) ) + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( all_par_vec_[arg] ) ) break; default: diff --git a/include/cppad/local/record/recorder.hpp b/include/cppad/local/record/recorder.hpp index 553dea6e0..e112f30b5 100644 --- a/include/cppad/local/record/recorder.hpp +++ b/include/cppad/local/record/recorder.hpp @@ -2,7 +2,7 @@ # define CPPAD_LOCAL_RECORD_RECORDER_HPP // 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 // ---------------------------------------------------------------------------- # include # include @@ -541,7 +541,7 @@ addr_t recorder::put_con_par(const Base &par) // index zero is used to signify that a value is not a parameter; // i.e., it is a variable. if( all_par_vec_.size() == 0 ) - CPPAD_ASSERT_UNKNOWN( isnan(par) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan(par) ); # endif // --------------------------------------------------------------------- // check for a match with a previous parameter diff --git a/include/cppad/local/val_graph/val2fun.hpp b/include/cppad/local/val_graph/val2fun.hpp index 0e6e21c39..3cce89213 100644 --- a/include/cppad/local/val_graph/val2fun.hpp +++ b/include/cppad/local/val_graph/val2fun.hpp @@ -2,7 +2,7 @@ # define CPPAD_LOCAL_VAL_GRAPH_VAL2FUN_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 // -------------------------------------------------------------------------- /* {xrst_begin val2fun_graph dev} @@ -228,7 +228,7 @@ void ADFun::val2fun( // initialize with the value nan at index nan par_addr = rec.put_con_par(nan); CPPAD_ASSERT_UNKNOWN( par_addr == 0 ); - CPPAD_ASSERT_UNKNOWN( isnan( parameter[par_addr] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[par_addr] ) ); // // rec // Place the variable with index 0 in the tape @@ -270,7 +270,7 @@ void ADFun::val2fun( fun_ad_type[ dyn_ind[i] ] = dynamic_enum; par_addr = rec.put_dyn_par(nan, local::ind_dyn); val2fun_index[ dyn_ind[i] ] = par_addr; - CPPAD_ASSERT_UNKNOWN( isnan( parameter[par_addr] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[par_addr] ) ); } // put the independent variables in the function recording for(size_t i = 0; i < var_n_ind; ++i) @@ -484,7 +484,7 @@ void ADFun::val2fun( CPPAD_VAL2FUN_DYN_BINARY(div); CPPAD_VAL2FUN_DYN_BINARY(pow); } - CPPAD_ASSERT_UNKNOWN( isnan( parameter[tmp_addr] ) ); + CPPAD_ASSERT_UNKNOWN( CppAD::isnan( parameter[tmp_addr] ) ); } else if( ad_type_x[0] == variable_enum && diff --git a/include/cppad/utility/nan.hpp b/include/cppad/utility/nan.hpp index 5a9e0bb68..8106fd99e 100644 --- a/include/cppad/utility/nan.hpp +++ b/include/cppad/utility/nan.hpp @@ -2,7 +2,7 @@ # define CPPAD_UTILITY_NAN_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 // ---------------------------------------------------------------------------- /* {xrst_begin nan} @@ -18,18 +18,24 @@ Syntax ****** | # ``include `` -| *b* = ``isnan`` ( *s* ) +| *b* = ``CppAD::isnan`` ( *s* ) *b* = ``hasnan`` ( *v* ) Purpose ******* -It obtain and check for the value not a number ``nan`` . +Check for the value not a number ``nan`` . The IEEE standard specifies that a floating point value *a* is ``nan`` if and only if the following returns true *a* != *a* +std::isnan +********** +Some compilers; e.g. Visual Studio, result in an ambiguous error +between ``CppAD::isnan`` and ``std::isnan`` unless you include the ``CppAD`` +before ``isnan`` (even when inside the CppAD namespace). + Include ******* The file ``cppad/utility/nan.hpp``