dconv 2.0
C++14 library for printing and parsing floating point numbers
Loading...
Searching...
No Matches
dconv::details Namespace Reference

Classes

struct  Power
 128 bits power. More...
 

Functions

constexpr bool isDigit (char c) noexcept
 
constexpr bool isSign (char c) noexcept
 
template<typename Probe >
bool readExponent (Probe &probe, int64_t &exponent)
 read an optional exponent.
 
template<typename Probe , bool Relaxed>
DCONV_COLD bool atodLong (Probe &probe, bool negative, uint64_t significand, int64_t &scale, bool fraction, double &value, int pending=-1)
 continue a conversion whose significand has more than 19 digits.
 
template<typename Probe , AtodMode Mode>
Errc atodRelaxed (Probe &probe, double &value, uint64_t &significand, int64_t &exponent, bool &negative)
 string to double conversion in general format that stops on integers.
 
template<typename Probe , AtodMode Mode>
DCONV_COLD Errc atodRewind (Probe &probe, double &value, uint64_t &significand, int64_t &exponent, bool &negative)
 parse again a number the fast path does not handle.
 
template<typename Probe , AtodMode Mode = AtodMode::General, bool Rewind = std::is_same_v<Probe, StringProbe>>
Errc atod (Probe &probe, double &value, uint64_t &significand, int64_t &exponent, bool &negative)
 string to double conversion that stops on integers.
 
template<typename Probe , AtodMode Mode = AtodMode::General>
bool atod (Probe &probe, double &value)
 string to double conversion.
 
int countTrailingZeros (uint32_t group) noexcept
 count the trailing zeros of a four digits group.
 
int countDigits (uint64_t digits) noexcept
 count the digits of a decimal significand.
 
int writeDigits (char *buffer, uint64_t digits, int length) noexcept
 write the digits of a decimal significand.
 
char * writeExponent (char *buffer, int k) noexcept
 write a decimal exponent.
 
char * prettify (char *buffer, int length, int k) noexcept
 lay out decimal digits as a fixed or scientific number.
 
char * format (char *buffer, uint64_t digits, int length, int k) noexcept
 write a decimal significand with the same layout as prettify.
 
void umul128 (uint64_t a, uint64_t b, uint64_t &high, uint64_t &low) noexcept
 multiply two 64 bits unsigned integers.
 

Variables

constexpr uint32_t pow10 [] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}
 powers of ten that fit in 32 bits.
 
constexpr char digitPairs []
 two digits decimal representations of 0 to 99.
 
constexpr uint8_t pairZeros []
 trailing zeros of the two digits decimal representations of 0 to 99.
 
constexpr Power eisellemirepow []
 
constexpr DiyFp grisupow []
 cached powers of ten for the grisu algorithms.
 
constexpr Power schubfachpow []
 

Function Documentation

◆ atod() [1/2]

template<typename Probe , AtodMode Mode = AtodMode::General>
bool dconv::details::atod ( Probe & probe,
double & value )
inline

string to double conversion.

Parameters
probeprobe to read from.
valueconverted value.
Returns
true on success, false otherwise.

◆ atod() [2/2]

template<typename Probe , AtodMode Mode = AtodMode::General, bool Rewind = std::is_same_v<Probe, StringProbe>>
Errc dconv::details::atod ( Probe & probe,
double & value,
uint64_t & significand,
int64_t & exponent,
bool & negative )
inline

string to double conversion that stops on integers.

Parameters
probeprobe to read from.
valueconverted value.
significandinteger value when the error is NotDouble, first significant digits read otherwise.
exponentdecimal exponent read.
negativesign read.
Returns
Errc::Success on success, the error otherwise.

◆ atodLong()

template<typename Probe , bool Relaxed>
DCONV_COLD bool dconv::details::atodLong ( Probe & probe,
bool negative,
uint64_t significand,
int64_t & scale,
bool fraction,
double & value,
int pending = -1 )

continue a conversion whose significand has more than 19 digits.

Parameters
probeprobe to read from, positioned on the first digit beyond the significand.
negativesign of the number.
significandfirst 19 significant digits.
scalepower of ten applied to the significand, updated with the final exponent.
fractiontrue if the reading stopped in the fractional part.
valueconverted value.
pendinginteger digit already read beyond the significand, or -1.
Returns
true on success, false otherwise.

◆ atodRelaxed()

template<typename Probe , AtodMode Mode>
Errc dconv::details::atodRelaxed ( Probe & probe,
double & value,
uint64_t & significand,
int64_t & exponent,
bool & negative )
inline

string to double conversion in general format that stops on integers.

Parameters
probeprobe to read from.
valueconverted value.
significandinteger value when the error is NotDouble, first significant digits read otherwise.
exponentdecimal exponent read.
negativesign read.
Returns
Errc::Success on success, the error otherwise.

◆ atodRewind()

template<typename Probe , AtodMode Mode>
DCONV_COLD Errc dconv::details::atodRewind ( Probe & probe,
double & value,
uint64_t & significand,
int64_t & exponent,
bool & negative )

parse again a number the fast path does not handle.

Parameters
probeprobe to read from, positioned on the start of the number.
valueconverted value.
significandinteger value when the error is NotDouble, first significant digits read otherwise.
exponentdecimal exponent read.
negativesign read.
Returns
Errc::Success on success, the error otherwise.

◆ countDigits()

int dconv::details::countDigits ( uint64_t digits)
inlinenoexcept

count the digits of a decimal significand.

Parameters
digitsdecimal significand.
Returns
number of digits.

◆ countTrailingZeros()

int dconv::details::countTrailingZeros ( uint32_t group)
inlinenoexcept

count the trailing zeros of a four digits group.

Parameters
groupfour digits group.
Returns
number of trailing zeros.

◆ format()

char * dconv::details::format ( char * buffer,
uint64_t digits,
int length,
int k )
inlinenoexcept

write a decimal significand with the same layout as prettify.

Parameters
bufferbuffer to write the string representation to.
digitsdecimal significand.
lengthnumber of digits.
kdecimal exponent.
Returns
end position.

◆ isDigit()

bool dconv::details::isDigit ( char c)
inlineconstexprnoexcept

◆ isSign()

bool dconv::details::isSign ( char c)
inlineconstexprnoexcept

◆ prettify()

char * dconv::details::prettify ( char * buffer,
int length,
int k )
inlinenoexcept

lay out decimal digits as a fixed or scientific number.

Parameters
bufferbuffer holding the digits.
lengthnumber of digits.
kdecimal exponent.
Returns
end position.

◆ readExponent()

template<typename Probe >
bool dconv::details::readExponent ( Probe & probe,
int64_t & exponent )
inline

read an optional exponent.

Parameters
probeprobe to read from.
exponentread exponent.
Returns
true on success, false otherwise.

◆ umul128()

void dconv::details::umul128 ( uint64_t a,
uint64_t b,
uint64_t & high,
uint64_t & low )
inlinenoexcept

multiply two 64 bits unsigned integers.

Parameters
amultiplicand.
bmultiplier.
highhigh 64 bits of the 128-bit result.
lowlow 64 bits of the 128-bit result.

◆ writeDigits()

int dconv::details::writeDigits ( char * buffer,
uint64_t digits,
int length )
inlinenoexcept

write the digits of a decimal significand.

Parameters
bufferbuffer to write the digits to.
digitsdecimal significand.
lengthnumber of digits.
Returns
number of trailing zeros written.

◆ writeExponent()

char * dconv::details::writeExponent ( char * buffer,
int k )
inlinenoexcept

write a decimal exponent.

Parameters
bufferbuffer to write the exponent to.
kexponent.
Returns
end position.

Variable Documentation

◆ digitPairs

char dconv::details::digitPairs[]
constexpr
Initial value:
=
"0001020304050607080910111213141516171819202122232425262728293031323334353637383940414243444546474849505152"
"5354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899"

two digits decimal representations of 0 to 99.

◆ eisellemirepow

Power dconv::details::eisellemirepow[]
constexpr

◆ grisupow

DiyFp dconv::details::grisupow[]
constexpr

cached powers of ten for the grisu algorithms.

◆ pairZeros

uint8_t dconv::details::pairZeros[]
constexpr
Initial value:
= {
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}

trailing zeros of the two digits decimal representations of 0 to 99.

◆ pow10

uint32_t dconv::details::pow10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}
constexpr

powers of ten that fit in 32 bits.

◆ schubfachpow

Power dconv::details::schubfachpow[]
constexpr