| 534 | |
| 535 | template <typename T> |
| 536 | T put_in_range ( |
| 537 | const T& a, |
| 538 | const T& b, |
| 539 | const T& val |
| 540 | ) |
| 541 | /*! |
| 542 | requires |
| 543 | - T is a type that looks like double, float, int, or so forth |
| 544 | ensures |
| 545 | - if (val is within the range [a,b]) then |
| 546 | - returns val |
| 547 | - else |
| 548 | - returns the end of the range [a,b] that is closest to val |
| 549 | !*/ |
| 550 | { |
| 551 | if (a < b) |
| 552 | { |
| 553 | if (val < a) |
| 554 | return a; |
| 555 | else if (val > b) |
| 556 | return b; |
| 557 | } |
| 558 | else |
| 559 | { |
| 560 | if (val < b) |
| 561 | return b; |
| 562 | else if (val > a) |
| 563 | return a; |
| 564 | } |
| 565 | |
| 566 | return val; |
| 567 | } |
| 568 | |
| 569 | // overload for double |
| 570 | inline double put_in_range(const double& a, const double& b, const double& val) |
no outgoing calls