MCPcopy Create free account
hub / github.com/fmtlib/fmt / write_exponent

Function write_exponent

include/fmt/format.h:1563–1586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1561// Writes the exponent exp in the form "[+-]d{2,3}" to buffer.
1562template <typename Char, typename OutputIt>
1563FMT_CONSTEXPR auto write_exponent(int exp, OutputIt out) -> OutputIt {
1564 FMT_ASSERT(-10000 < exp && exp < 10000, "exponent out of range");
1565 if (exp < 0) {
1566 *out++ = static_cast<Char>('-');
1567 exp = -exp;
1568 } else {
1569 *out++ = static_cast<Char>('+');
1570 }
1571 auto uexp = static_cast<uint32_t>(exp);
1572 if (is_constant_evaluated()) {
1573 if (uexp < 10) *out++ = '0';
1574 return format_decimal<Char>(out, uexp, count_digits(uexp));
1575 }
1576 if (uexp >= 100u) {
1577 const char* top = digits2(uexp / 100);
1578 if (uexp >= 1000u) *out++ = static_cast<Char>(top[0]);
1579 *out++ = static_cast<Char>(top[1]);
1580 uexp %= 100;
1581 }
1582 const char* d = digits2(uexp);
1583 *out++ = static_cast<Char>(d[0]);
1584 *out++ = static_cast<Char>(d[1]);
1585 return out;
1586}
1587
1588// A floating-point number f * pow(2, e) where F is an unsigned type.
1589template <typename F> struct basic_fp {

Callers

nothing calls this directly

Calls 3

is_constant_evaluatedFunction · 0.85
count_digitsFunction · 0.85
digits2Function · 0.85

Tested by

no test coverage detected