| 679 | |
| 680 | template <class T, class U, class Policy> |
| 681 | inline typename tools::promote_args<T, U>::type float_distance(const T& a, const U& b, const Policy& pol) |
| 682 | { |
| 683 | // |
| 684 | // We allow ONE of a and b to be an integer type, otherwise both must be the SAME type. |
| 685 | // |
| 686 | static_assert( |
| 687 | (std::is_same<T, U>::value |
| 688 | || (std::is_integral<T>::value && !std::is_integral<U>::value) |
| 689 | || (!std::is_integral<T>::value && std::is_integral<U>::value) |
| 690 | || (std::numeric_limits<T>::is_specialized && std::numeric_limits<U>::is_specialized |
| 691 | && (std::numeric_limits<T>::digits == std::numeric_limits<U>::digits) |
| 692 | && (std::numeric_limits<T>::radix == std::numeric_limits<U>::radix) |
| 693 | && !std::numeric_limits<T>::is_integer && !std::numeric_limits<U>::is_integer)), |
| 694 | "Float distance between two different floating point types is undefined."); |
| 695 | |
| 696 | BOOST_IF_CONSTEXPR (!std::is_same<T, U>::value) |
| 697 | { |
| 698 | BOOST_IF_CONSTEXPR(std::is_integral<T>::value) |
| 699 | { |
| 700 | return float_distance(static_cast<U>(a), b, pol); |
| 701 | } |
| 702 | else |
| 703 | { |
| 704 | return float_distance(a, static_cast<T>(b), pol); |
| 705 | } |
| 706 | } |
| 707 | else |
| 708 | { |
| 709 | typedef typename tools::promote_args<T, U>::type result_type; |
no test coverage detected