| 134 | template <typename To, typename From, |
| 135 | FMT_ENABLE_IF(!std::is_same<From, To>::value)> |
| 136 | FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) { |
| 137 | ec = 0; |
| 138 | using T = std::numeric_limits<To>; |
| 139 | static_assert(std::is_floating_point<From>::value, "From must be floating"); |
| 140 | static_assert(std::is_floating_point<To>::value, "To must be floating"); |
| 141 | |
| 142 | // catch the only happy case |
| 143 | if (std::isfinite(from)) { |
| 144 | if (from >= T::lowest() && from <= T::max()) { |
| 145 | return static_cast<To>(from); |
| 146 | } |
| 147 | // not within range. |
| 148 | ec = 1; |
| 149 | return {}; |
| 150 | } |
| 151 | |
| 152 | // nan and inf will be preserved |
| 153 | return static_cast<To>(from); |
| 154 | } // function |
| 155 | |
| 156 | template <typename To, typename From, |
| 157 | FMT_ENABLE_IF(std::is_same<From, To>::value)> |
nothing calls this directly
no test coverage detected