MCPcopy Create free account
hub / github.com/Gecode/gecode / pow

Function pow

gecode/third-party/boost/numeric/interval/arith2.hpp:157–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155} // namespace interval_lib
156
157template<class T, class Policies> inline
158interval<T, Policies> pow(const interval<T, Policies>& x, int pwr)
159{
160 GECODE_BOOST_USING_STD_MAX();
161 using interval_lib::detail::pow_dn;
162 using interval_lib::detail::pow_up;
163 typedef interval<T, Policies> I;
164
165 if (interval_lib::detail::test_input(x))
166 return I::empty();
167
168 if (pwr == 0)
169 if (interval_lib::user::is_zero(x.lower())
170 && interval_lib::user::is_zero(x.upper()))
171 return I::empty();
172 else
173 return I(static_cast<T>(1));
174 else if (pwr < 0)
175 return interval_lib::multiplicative_inverse(pow(x, -pwr));
176
177 typename Policies::rounding rnd;
178
179 if (interval_lib::user::is_neg(x.upper())) { // [-2,-1]
180 T yl = pow_dn(static_cast<T>(-x.upper()), pwr, rnd);
181 T yu = pow_up(static_cast<T>(-x.lower()), pwr, rnd);
182 if (pwr & 1) // [-2,-1]^1
183 return I(-yu, -yl, true);
184 else // [-2,-1]^2
185 return I(yl, yu, true);
186 } else if (interval_lib::user::is_neg(x.lower())) { // [-1,1]
187 if (pwr & 1) { // [-1,1]^1
188 return I(-pow_up(static_cast<T>(-x.lower()), pwr, rnd), pow_up(x.upper(), pwr, rnd), true);
189 } else { // [-1,1]^2
190 return I(static_cast<T>(0), pow_up(max GECODE_BOOST_PREVENT_MACRO_SUBSTITUTION(static_cast<T>(-x.lower()), x.upper()), pwr, rnd), true);
191 }
192 } else { // [1,2]
193 return I(pow_dn(x.lower(), pwr, rnd), pow_up(x.upper(), pwr, rnd), true);
194 }
195}
196
197template<class T, class Policies> inline
198interval<T, Policies> sqrt(const interval<T, Policies>& x)

Callers 1

root_auxFunction · 0.70

Calls 10

test_inputFunction · 0.85
is_zeroFunction · 0.85
multiplicative_inverseFunction · 0.85
is_negFunction · 0.85
pow_dnFunction · 0.85
pow_upFunction · 0.85
emptyFunction · 0.70
lowerMethod · 0.45
upperMethod · 0.45

Tested by

no test coverage detected