MCPcopy Create free account
hub / github.com/ablab/spades / format_decimal

Function format_decimal

ext/include/cppformat/format.h:552–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550// Formats a decimal unsigned integer value writing into buffer.
551template <typename UInt, typename Char>
552inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
553 --num_digits;
554 while (value >= 100) {
555 // Integer division is slow so do it for a group of two digits instead
556 // of for every digit. The idea comes from the talk by Alexandrescu
557 // "Three Optimization Tips for C++". See speed-test for a comparison.
558 unsigned index = (value % 100) * 2;
559 value /= 100;
560 buffer[num_digits] = DIGITS[index + 1];
561 buffer[num_digits - 1] = DIGITS[index];
562 num_digits -= 2;
563 }
564 if (value < 10) {
565 *buffer = static_cast<char>('0' + value);
566 return;
567 }
568 unsigned index = static_cast<unsigned>(value * 2);
569 buffer[1] = DIGITS[index + 1];
570 buffer[0] = DIGITS[index];
571}
572
573#ifdef _WIN32
574// A converter from UTF-8 to UTF-16.

Callers 4

write_intMethod · 0.70
FormatSignedMethod · 0.70
FormatIntMethod · 0.70
format_decimalMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected