| 745 | */ |
| 746 | template<typename T_IN, typename T_OUT> |
| 747 | bool numericCast(T_IN in, T_OUT& out) |
| 748 | { |
| 749 | if (std::is_same<T_IN, T_OUT>::value) |
| 750 | { |
| 751 | out = static_cast<T_OUT>(in); |
| 752 | return true; |
| 753 | } |
| 754 | if (std::is_integral<T_OUT>::value) |
| 755 | in = static_cast<T_IN>(sround((double)in)); |
| 756 | if ((std::is_same<T_OUT, double>::value) || |
| 757 | (in <= static_cast<double>((std::numeric_limits<T_OUT>::max)()) && |
| 758 | in >= static_cast<double>(std::numeric_limits<T_OUT>::lowest()))) |
| 759 | { |
| 760 | out = static_cast<T_OUT>(in); |
| 761 | return true; |
| 762 | } |
| 763 | return false; |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | Convert a numeric value from double to float. Specialization to handle |