Public Member Functions | Private Member Functions | Private Attributes | List of all members
internal::decimal_formatter Class Reference

#include <format.h>

Inheritance diagram for internal::decimal_formatter:
internal::decimal_formatter_null

Public Member Functions

 decimal_formatter (char *buf)
 
template<unsigned N>
char * on (uint32_t u)
 

Private Member Functions

void write_pair (unsigned N, uint32_t index)
 

Private Attributes

char * buffer_
 

Detailed Description

Definition at line 847 of file format.h.

Constructor & Destructor Documentation

internal::decimal_formatter::decimal_formatter ( char *  buf)
inlineexplicit

Definition at line 856 of file format.h.

856 : buffer_(buf) {}

Member Function Documentation

template<unsigned N>
char* internal::decimal_formatter::on ( uint32_t  u)
inline

Definition at line 858 of file format.h.

858  {
859  if (N == 0) {
860  *buffer_ = static_cast<char>(u) + '0';
861  } else if (N == 1) {
862  write_pair(0, u);
863  } else {
864  // The idea of using 4.32 fixed-point numbers is based on
865  // https://github.com/jeaiii/itoa
866  unsigned n = N - 1;
867  unsigned a = n / 5 * n * 53 / 16;
868  uint64_t t = ((1ULL << (32 + a)) /
869  data::ZERO_OR_POWERS_OF_10_32[n] + 1 - n / 9);
870  t = ((t * u) >> a) + n / 5 * 4;
871  write_pair(0, t >> 32);
872  for (unsigned i = 2; i < N; i += 2) {
873  t = 100ULL * static_cast<uint32_t>(t);
874  write_pair(i, t >> 32);
875  }
876  if (N % 2 == 0) {
877  buffer_[N] = static_cast<char>(
878  (10ULL * static_cast<uint32_t>(t)) >> 32) + '0';
879  }
880  }
881  return buffer_ += N + 1;
882  }
unsigned int uint32_t
Definition: stdint.h:126
unsigned __int64 uint64_t
Definition: stdint.h:136
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
void write_pair(unsigned N, uint32_t index)
Definition: format.h:851
static const uint32_t ZERO_OR_POWERS_OF_10_32[]
Definition: format.h:749
std::size_t n
Definition: format.h:3399
void internal::decimal_formatter::write_pair ( unsigned  N,
uint32_t  index 
)
inlineprivate

Definition at line 851 of file format.h.

851  {
852  std::memcpy(buffer_ + N, data::DIGITS + index * 2, 2);
853  }
static const char DIGITS[]
Definition: format.h:753

Member Data Documentation

char* internal::decimal_formatter::buffer_
private

Definition at line 849 of file format.h.


The documentation for this class was generated from the following file: