48 template<
typename _Tp>
51 return ((val > (_Tp)0) ? val : -val);
55 template<
typename _Tp>
56 inline const _Tp
goldensection(
const _Tp &arg1,
const _Tp &arg2, _Tp(*fun)(_Tp),
const _Tp &tol)
60 _Tp c = b - (b - a) / GOLDEN_RATIO;
61 _Tp d = a + (b - a) / GOLDEN_RATIO;
63 while (
abs_t(c - d) > tol) {
65 if (fun(c) < fun(d)) {
72 c = b - (b - a) / GOLDEN_RATIO;
73 d = a + (b - a) / GOLDEN_RATIO;
77 return ((b + a) / (_Tp)2);
const _Tp goldensection(const _Tp &arg1, const _Tp &arg2, _Tp(*fun)(_Tp), const _Tp &tol)
static constexpr double GOLDEN_RATIO