MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / handle_zero_derivative

Function handle_zero_derivative

extern/boost/boost/math/tools/roots.hpp:78–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76
77template <class F, class T>
78void handle_zero_derivative(F f,
79 T& last_f0,
80 const T& f0,
81 T& delta,
82 T& result,
83 T& guess,
84 const T& min,
85 const T& max) noexcept(BOOST_MATH_IS_FLOAT(T) && noexcept(std::declval<F>()(std::declval<T>())))
86{
87 if (last_f0 == 0)
88 {
89 // this must be the first iteration, pretend that we had a
90 // previous one at either min or max:
91 if (result == min)
92 {
93 guess = max;
94 }
95 else
96 {
97 guess = min;
98 }
99 unpack_0(f(guess), last_f0);
100 delta = guess - result;
101 }
102 if (sign(last_f0) * sign(f0) < 0)
103 {
104 // we've crossed over so move in opposite direction to last step:
105 if (delta < 0)
106 {
107 delta = (result - min) / 2;
108 }
109 else
110 {
111 delta = (result - max) / 2;
112 }
113 }
114 else
115 {
116 // move in same direction as last step:
117 if (delta < 0)
118 {
119 delta = (result - max) / 2;
120 }
121 else
122 {
123 delta = (result - min) / 2;
124 }
125 }
126}
127
128} // namespace
129

Callers 2

newton_raphson_iterateFunction · 0.85
second_order_root_finderFunction · 0.85

Calls 1

signFunction · 0.85

Tested by

no test coverage detected