Audacity  3.2.0
Classes | Namespaces | Macros | Functions | Variables
ToChars.cpp File Reference
#include "ToChars.h"
#include <array>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <numeric>
Include dependency graph for ToChars.cpp:

Go to the source code of this file.

Classes

struct  internal::itoa_impl::pair
 
struct  internal::dtoa_impl::diyfp
 
struct  internal::dtoa_impl::boundaries
 
struct  internal::dtoa_impl::cached_power
 

Namespaces

 internal
 
 internal::itoa_impl
 
 internal::dtoa_impl
 

Macros

#define P(T)   T, '0', T, '1', T, '2', T, '3', T, '4', T, '5', T, '6', T, '7', T, '8', T, '9'
 
#define W(N, I)   *(pair*)&b[N] = s_pairs[I]
 
#define A(N)   t = (uint64_t(1) << (32 + N / 5 * N * 53 / 16)) / uint32_t(1e##N) + 1 + N / 6 - N / 8, t *= u, t >>= N / 5 * N * 53 / 16, t += N / 6 * 4, W(0, t >> 32)
 
#define S(N)   b[N] = char(uint64_t(10) * uint32_t(t) >> 32) + '0'
 
#define D(N)   t = uint64_t(100) * uint32_t(t), W(N, t >> 32)
 
#define L0   b[0] = char(u) + '0'
 
#define L1   W(0, u)
 
#define L2   A(1), S(2)
 
#define L3   A(2), D(2)
 
#define L4   A(3), D(2), S(4)
 
#define L5   A(4), D(2), D(4)
 
#define L6   A(5), D(2), D(4), S(6)
 
#define L7   A(6), D(2), D(4), D(6)
 
#define L8   A(7), D(2), D(4), D(6), S(8)
 
#define L9   A(8), D(2), D(4), D(6), D(8)
 
#define LN(N)   (L##N, b += N + 1)
 
#define LZ   LN
 
#define LG(F)
 

Functions

char * internal::itoa_impl::u64toa_jeaiii (uint64_t n, char *b)
 
template<typename Target , typename Source >
Target internal::dtoa_impl::reinterpret_bits (const Source source)
 
template<typename FloatType >
boundaries internal::dtoa_impl::compute_boundaries (FloatType value)
 
cached_power internal::dtoa_impl::get_cached_power_for_binary_exponent (int e)
 
int internal::dtoa_impl::find_largest_pow10 (const std::uint32_t n, std::uint32_t &pow10)
 
void internal::dtoa_impl::grisu2_round (char *buf, int len, std::uint64_t dist, std::uint64_t delta, std::uint64_t rest, std::uint64_t ten_k)
 
bool internal::dtoa_impl::grisu2_digit_gen (char *buffer, char *last, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
 
bool internal::dtoa_impl::grisu2 (char *buf, char *last, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
 
template<typename FloatType >
bool internal::dtoa_impl::grisu2 (char *buf, char *last, int &len, int &decimal_exponent, FloatType value)
 
ToCharsResult internal::dtoa_impl::append_exponent (char *buf, char *last, int e)
 appends a decimal representation of e to buf More...
 
ToCharsResult internal::dtoa_impl::format_buffer (char *buf, char *last, int len, int decimal_exponent, int min_exp, int max_exp)
 prettify v = buf * 10^decimal_exponent If v is in the range [10^min_exp, 10^max_exp) it will be printed in fixed-point notation. Otherwise it will be printed in exponential notation. More...
 
template<typename T >
ToCharsResult internal::float_to_chars (char *first, char *last, T value, int digitsAfterDecimalPoint)
 
STRING_UTILS_API ToCharsResult ToChars (char *buffer, char *last, float value, int digitsAfterDecimalPoint) noexcept
 Convert a single precision floating point number to a string, always uses the dot as decimal. More...
 
STRING_UTILS_API ToCharsResult ToChars (char *buffer, char *last, double value, int digitsAfterDecimalPoint) noexcept
 Convert a double precision floating point number to a string, always uses the dot as decimal. More...
 
ToCharsResult ToChars (char *buffer, char *last, long long value) noexcept
 Convert a signed 64 bit integer value to string. More...
 
ToCharsResult ToChars (char *buffer, char *last, unsigned long long value) noexcept
 Convert a unsigned 64 bit integer value to string. More...
 

Variables

static const pair internal::itoa_impl::s_pairs [] = { P('0'), P('1'), P('2'), P('3'), P('4'), P('5'), P('6'), P('7'), P('8'), P('9') }
 
constexpr int internal::dtoa_impl::kAlpha = -60
 
constexpr int internal::dtoa_impl::kGamma = -32
 

Macro Definition Documentation

◆ A

#define A (   N)    t = (uint64_t(1) << (32 + N / 5 * N * 53 / 16)) / uint32_t(1e##N) + 1 + N / 6 - N / 8, t *= u, t >>= N / 5 * N * 53 / 16, t += N / 6 * 4, W(0, t >> 32)

Definition at line 62 of file ToChars.cpp.

◆ D

#define D (   N)    t = uint64_t(100) * uint32_t(t), W(N, t >> 32)

Definition at line 66 of file ToChars.cpp.

◆ L0

#define L0   b[0] = char(u) + '0'

Definition at line 68 of file ToChars.cpp.

◆ L1

#define L1   W(0, u)

Definition at line 69 of file ToChars.cpp.

◆ L2

#define L2   A(1), S(2)

Definition at line 70 of file ToChars.cpp.

◆ L3

#define L3   A(2), D(2)

Definition at line 71 of file ToChars.cpp.

◆ L4

#define L4   A(3), D(2), S(4)

Definition at line 72 of file ToChars.cpp.

◆ L5

#define L5   A(4), D(2), D(4)

Definition at line 73 of file ToChars.cpp.

◆ L6

#define L6   A(5), D(2), D(4), S(6)

Definition at line 74 of file ToChars.cpp.

◆ L7

#define L7   A(6), D(2), D(4), D(6)

Definition at line 75 of file ToChars.cpp.

◆ L8

#define L8   A(7), D(2), D(4), D(6), S(8)

Definition at line 76 of file ToChars.cpp.

◆ L9

#define L9   A(8), D(2), D(4), D(6), D(8)

Definition at line 77 of file ToChars.cpp.

◆ LG

#define LG (   F)
Value:
(u < 100 ? u < 10 ? F(0) : F(1) : \
u < 1000000 ? u < 10000 ? u < 1000 ? F(2) : F(3) : \
u < 100000 ? F(4) : \
F(5) : \
u < 100000000 ? u < 10000000 ? F(6) : F(7) : \
u < 1000000000 ? F(8) : \
F(9))

Definition at line 84 of file ToChars.cpp.

◆ LN

#define LN (   N)    (L##N, b += N + 1)

Definition at line 79 of file ToChars.cpp.

◆ LZ

#define LZ   LN

Definition at line 80 of file ToChars.cpp.

◆ P

#define P (   T)    T, '0', T, '1', T, '2', T, '3', T, '4', T, '5', T, '6', T, '7', T, '8', T, '9'

Definition at line 56 of file ToChars.cpp.

◆ S

#define S (   N)    b[N] = char(uint64_t(10) * uint32_t(t) >> 32) + '0'

Definition at line 64 of file ToChars.cpp.

◆ W

#define W (   N,
 
)    *(pair*)&b[N] = s_pairs[I]

Definition at line 60 of file ToChars.cpp.

Function Documentation

◆ ToChars() [1/4]

STRING_UTILS_API ToCharsResult ToChars ( char *  buffer,
char *  last,
double  value,
int  digitsAfterDecimalPoint 
)
noexcept

Convert a double precision floating point number to a string, always uses the dot as decimal.

Definition at line 1233 of file ToChars.cpp.

1236 {
1237  return internal::float_to_chars(
1238  buffer, last, value, digitsAfterDecimalPoint);
1239 }

References internal::float_to_chars().

Here is the call graph for this function:

◆ ToChars() [2/4]

STRING_UTILS_API ToCharsResult ToChars ( char *  buffer,
char *  last,
float  value,
int  digitsAfterDecimalPoint 
)
noexcept

Convert a single precision floating point number to a string, always uses the dot as decimal.

Definition at line 1225 of file ToChars.cpp.

1228 {
1229  return internal::float_to_chars(
1230  buffer, last, value, digitsAfterDecimalPoint);
1231 }

References internal::float_to_chars().

Referenced by ToChars(), and XMLUtf8BufferWriter::WriteAttr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToChars() [3/4]

ToCharsResult ToChars ( char *  buffer,
char *  last,
long long  value 
)
noexcept

Convert a signed 64 bit integer value to string.

Definition at line 1242 of file ToChars.cpp.

1243 {
1244  if (buffer >= last || buffer == nullptr)
1245  return { last, std::errc::value_too_large };
1246 
1247  if (value < 0)
1248  {
1249  *buffer++ = '-';
1250  value = -value;
1251  }
1252 
1253  return ToChars(buffer, last, static_cast<unsigned long long>(value));
1254 }

References ToChars().

Here is the call graph for this function:

◆ ToChars() [4/4]

ToCharsResult ToChars ( char *  buffer,
char *  last,
unsigned long long  value 
)
noexcept

Convert a unsigned 64 bit integer value to string.

Definition at line 1256 of file ToChars.cpp.

1257 {
1258  if (buffer >= last || buffer == nullptr)
1259  return { last, std::errc::value_too_large };
1260 
1261  if (value == 0)
1262  {
1263  *buffer++ = '0';
1264  return { buffer, std::errc() };
1265  }
1266 
1267  constexpr size_t safeSize =
1268  std::numeric_limits<unsigned long long>::digits10 + 2;
1269 
1270  const size_t bufferSize = static_cast<size_t>(last - buffer);
1271 
1272  if (bufferSize >= safeSize)
1273  return { internal::itoa_impl::u64toa_jeaiii(value, buffer), std::errc() };
1274 
1275  char tempBuffer[safeSize];
1276  char* tempLast = internal::itoa_impl::u64toa_jeaiii(value, tempBuffer);
1277 
1278  const size_t resultSize = static_cast<size_t>(tempLast - tempBuffer);
1279 
1280  if (resultSize > bufferSize)
1281  return { last, std::errc::value_too_large };
1282 
1283  std::copy(tempBuffer, tempLast, buffer);
1284 
1285  return { buffer + resultSize, std::errc() };
1286 }

References internal::itoa_impl::u64toa_jeaiii().

Here is the call graph for this function:
internal::float_to_chars
ToCharsResult float_to_chars(char *first, char *last, T value, int digitsAfterDecimalPoint)
Definition: ToChars.cpp:1178
ToChars
STRING_UTILS_API ToCharsResult ToChars(char *buffer, char *last, float value, int digitsAfterDecimalPoint) noexcept
Convert a single precision floating point number to a string, always uses the dot as decimal.
Definition: ToChars.cpp:1225
internal::itoa_impl::u64toa_jeaiii
char * u64toa_jeaiii(uint64_t n, char *b)
Definition: ToChars.cpp:93