| 292 | |
| 293 | template <typename T> |
| 294 | T constrain_value(const T amt, const T low, const T high) |
| 295 | { |
| 296 | // the check for NaN as a float prevents propagation of floating point |
| 297 | // errors through any function that uses constrain_value(). The normal |
| 298 | // float semantics already handle -Inf and +Inf |
| 299 | if (std::is_floating_point<T>::value) { |
| 300 | if (isnan(amt)) { |
| 301 | INTERNAL_ERROR(AP_InternalError::error_t::constraining_nan); |
| 302 | return (low + high) / 2; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if (amt < low) { |
| 307 | return low; |
| 308 | } |
| 309 | |
| 310 | if (amt > high) { |
| 311 | return high; |
| 312 | } |
| 313 | |
| 314 | return amt; |
| 315 | } |
| 316 | |
| 317 | template int constrain_value<int>(const int amt, const int low, const int high); |
| 318 | template unsigned int constrain_value<unsigned int>(const unsigned int amt, const unsigned int low, const unsigned int high); |
no outgoing calls