MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / safe_float_conversion

Function safe_float_conversion

extlibs/fmt/include/fmt/chrono.h:136–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134template <typename To, typename From,
135 FMT_ENABLE_IF(!std::is_same<From, To>::value)>
136FMT_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
156template <typename To, typename From,
157 FMT_ENABLE_IF(std::is_same<From, To>::value)>

Callers

nothing calls this directly

Calls 1

isfiniteFunction · 0.85

Tested by

no test coverage detected