Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_ABSOLUTE_CONVERGENCE_H
00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_ABSOLUTE_CONVERGENCE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_value_traits.h>
00013 #include <OpenTissue/core/math/math_is_number.h>
00014
00015 #include <cmath>
00016
00017 namespace OpenTissue
00018 {
00019 namespace math
00020 {
00021 namespace optimization
00022 {
00023
00034 template < typename T >
00035 inline bool absolute_convergence(
00036 T const & f
00037 , T const & tolerance
00038 )
00039 {
00040 using std::fabs;
00041
00042 typedef OpenTissue::math::ValueTraits<T> value_traits;
00043
00044 assert( tolerance >= value_traits::zero() || !"absolute_convergence(): tolerance must be non-negative");
00045 assert( is_number( tolerance ) || !"absolute_convergence(): internal error, NAN is encountered?");
00046 assert( is_number( f ) || !"absolute_convergence(): internal error, NAN is encountered?");
00047
00048 if(f <= tolerance)
00049 return true;
00050
00051 return false;
00052 }
00053
00054 }
00055 }
00056 }
00057
00058
00059 #endif