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

Method do_write_float

include/fmt/format.h:2588–2624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2586template <typename Char, typename Grouping, typename OutputIt,
2587 typename DecimalFP>
2588FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
2589 const format_specs& specs, sign s,
2590 int exp_upper, locale_ref loc) -> OutputIt {
2591 Char point = specs.localized() ? detail::decimal_point<Char>(loc) : Char('.');
2592 int significand_size = get_significand_size(f);
2593 int exp = f.exponent + significand_size - 1;
2594 if (specs.type() == presentation_type::fixed ||
2595 (specs.type() != presentation_type::exp &&
2596 use_fixed(exp, specs.precision > 0 ? specs.precision : exp_upper))) {
2597 return write_fixed<Char, Grouping>(out, f, significand_size, point, specs,
2598 s, loc);
2599 }
2600
2601 // Write value in the exponential format.
2602 int num_zeros = 0;
2603 long long size = significand_size + (s != sign::none ? 1 : 0);
2604 if (specs.alt()) {
2605 num_zeros = max_of(specs.precision - significand_size, 0);
2606 size += num_zeros;
2607 } else if (significand_size == 1) {
2608 point = Char();
2609 }
2610 size += (point ? 1 : 0) + compute_exp_size(exp);
2611 char exp_char = specs.upper() ? 'E' : 'e';
2612 auto write = [=](reserve_iterator<OutputIt> it) {
2613 if (s != sign::none) *it++ = detail::getsign<Char>(s);
2614 // Insert a decimal point after the first digit and add an exponent.
2615 it = write_significand(it, f.significand, significand_size, 1, point);
2616 if (num_zeros > 0) it = detail::fill_n(it, num_zeros, Char('0'));
2617 *it++ = Char(exp_char);
2618 return write_exponent<Char>(exp, it);
2619 };
2620 size_t usize = static_cast<size_t>(size);
2621 return specs.width > 0
2622 ? write_padded<Char, align::right>(out, specs, usize, write)
2623 : base_iterator(out, write(reserve(out, usize)));
2624}
2625
2626template <typename Char, typename OutputIt, typename DecimalFP>
2627FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f,

Callers

nothing calls this directly

Calls 10

max_ofFunction · 0.85
compute_exp_sizeFunction · 0.85
fill_nFunction · 0.85
base_iteratorFunction · 0.85
altMethod · 0.80
upperMethod · 0.80
writeFunction · 0.70
reserveFunction · 0.70
localizedMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected