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

Function lossless_integral_conversion

extlibs/fmt/include/fmt/chrono.h:39–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 std::numeric_limits<From>::is_signed ==
38 std::numeric_limits<To>::is_signed)>
39FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
40 ec = 0;
41 using F = std::numeric_limits<From>;
42 using T = std::numeric_limits<To>;
43 static_assert(F::is_integer, "From must be integral");
44 static_assert(T::is_integer, "To must be integral");
45
46 // A and B are both signed, or both unsigned.
47 if (F::digits <= T::digits) {
48 // From fits in To without any problem.
49 } else {
50 // From does not always fit in To, resort to a dynamic check.
51 if (from < T::min() || from > T::max()) {
52 // outside range.
53 ec = 1;
54 return {};
55 }
56 }
57 return static_cast<To>(from);
58}
59
60/**
61 * converts From to To, without loss. If the dynamic value of from

Callers

nothing calls this directly

Calls 1

is_negativeFunction · 0.85

Tested by

no test coverage detected