46 #include <private/qnumeric_p.h>
59 #if defined(Q_OS_LINUX) && !defined(__UCLIBC__)
65 # define LLONG_MAX Q_INT64_C(0x7fffffffffffffff)
68 # define LLONG_MIN (-LLONG_MAX - Q_INT64_C(1))
71 # define ULLONG_MAX Q_UINT64_C(0xffffffffffffffff)
79 bool &sign,
int &
length,
int &decpt)
104 }
else if (qt_is_nan(
d)) {
119 #if !defined(QT_NO_DOUBLECONVERSION) && !defined(QT_BOOTSTRAPPED)
143 precision = std::numeric_limits<double>::max_digits10;
159 const int formatLength = 7;
160 char format[formatLength];
161 format[formatLength - 1] =
'\0';
170 format[formatLength - 2] =
'f';
175 format[formatLength - 2] =
'e';
180 format[formatLength - 2] =
'g';
193 int firstSignificant = 0;
194 int decptInTarget =
length;
198 while (firstSignificant <
length) {
199 if (
target[firstSignificant] ==
'.')
200 decptInTarget = firstSignificant;
201 else if (
target[firstSignificant] !=
'0')
207 if (decptInTarget ==
length)
234 decpt = decptInTarget - firstSignificant;
239 decpt = decptInTarget - firstSignificant;
243 if (decptInTarget > firstSignificant) {
245 int lengthBeforeDecpt = decptInTarget - firstSignificant;
246 memcpy(
buf,
target.data() + firstSignificant, qMin(lengthBeforeDecpt,
bufSize));
247 if (eSign > decptInTarget && lengthBeforeDecpt <
bufSize) {
249 memcpy(
buf + lengthBeforeDecpt,
target.data() + decptInTarget + 1,
250 qMin(eSign - decptInTarget - 1,
bufSize - lengthBeforeDecpt));
259 if (eSign > firstSignificant) {
262 memcpy(
buf,
target.data() + firstSignificant, qMin(eSign - firstSignificant,
bufSize));
284 auto string_equals = [](
const char *needle,
const char *haystack,
qsizetype haystackLen) {
286 return needleLen == haystackLen && memcmp(needle, haystack, haystackLen) == 0;
300 if (string_equals(
"nan",
num, numLen)) {
303 }
else if (string_equals(
"+nan",
num, numLen) || string_equals(
"-nan",
num, numLen)) {
311 if (string_equals(
"+inf",
num, numLen)) {
314 }
else if (string_equals(
"inf",
num, numLen)) {
317 }
else if (string_equals(
"-inf",
num, numLen)) {
323 #if !defined(QT_NO_DOUBLECONVERSION) && !defined(QT_BOOTSTRAPPED)
332 if (
int(numLen) != numLen) {
354 constexpr
auto maxDigitsForULongLong = 1 + std::numeric_limits<unsigned long long>::digits10;
356 char fmt[1 + maxDigitsForULongLong + 4 + 1];
357 sprintf(fmt,
"%s%llu%s",
"%",
static_cast<unsigned long long>(numLen),
"lf%n");
359 if (qDoubleSscanf(
num, QT_CLOCALE, fmt, &
d, &processed) < 1)
374 for (
int i = 0;
i < processed; ++
i) {
391 for (
int i = 0;
i < processed; ++
i) {
392 if (
num[
i] >=
'1' &&
num[
i] <=
'9') {
396 }
else if (
num[
i] ==
'e' ||
num[
i] ==
'E') {
405 static auto scanPrefix(
const char *
p,
const char *stop,
int base)
409 const char *
x =
p + 1;
410 if (
x < stop && (*
x ==
'x' || *
x ==
'X')) {
415 }
else if (
base == 0) {
418 }
else if (
base == 0) {
431 static bool isDigitForBase(
char d,
int base)
435 if (
d -
'0' < qMin(
base, 10))
439 return d >=
'a' &&
d <
'a' +
base - 10;
450 unsigned long long result = 0;
451 if (
p >= stop || *
p ==
'-') {
457 const auto prefix = scanPrefix(*
p ==
'+' ?
p + 1 :
p, stop,
base);
458 if (!prefix.base || prefix.next >= stop) {
465 const auto res = std::from_chars(prefix.next, stop,
result, prefix.base);
466 *
ok =
res.ec == std::errc{};
468 *endptr =
res.ptr == prefix.next ?
begin :
res.ptr;
481 const bool negate =
p < stop && *
p ==
'-';
482 if (negate || (
p < stop && *
p ==
'+'))
485 const auto prefix = scanPrefix(
p, stop,
base);
488 if (!prefix.base || prefix.next >= stop || !isDigitForBase(*prefix.next, prefix.base)) {
496 auto res = std::from_chars(prefix.next, stop,
result, prefix.base);
497 *
ok =
res.ec == std::errc{};
498 if (negate &&
res.ec == std::errc::result_out_of_range) {
500 unsigned long long check = 0;
501 res = std::from_chars(prefix.next, stop, check, prefix.base);
502 if (
res.ec == std::errc{} && check + std::numeric_limits<long long>::min() == 0) {
506 return std::numeric_limits<long long>::min();
510 *endptr =
res.ptr == prefix.next ?
begin :
res.ptr;
514 template <
typename Char>
519 #define BIG_BASE_LOOP(b) \
521 const int r = number % b; \
522 *--p = Char((r < 10 ? '0' : 'a' - 10) + r); \
525 #ifndef __OPTIMIZE_SIZE__
526 # define SMALL_BASE_LOOP(b) \
528 *--p = Char('0' + number % b); \
536 #undef SMALL_BASE_LOOP
550 const unsigned maxlen = 65;
551 static_assert(CHAR_BIT *
sizeof(
number) + 1 <= maxlen);
552 char16_t buff[maxlen];
553 char16_t *
const end = buff + maxlen, *
p =
end;
566 const unsigned maxlen = 128;
567 static_assert(CHAR_BIT *
sizeof(
number) <= maxlen);
568 char16_t buff[maxlen];
569 char16_t *
const end = buff + maxlen, *
p =
end;
573 }
else if (
zero.size() && !
zero.at(0).isSurrogate()) {
574 const char16_t zeroUcs2 =
zero.at(0).unicode();
580 }
else if (
zero.size() == 2 &&
zero.at(0).isHighSurrogate()) {
606 bool nonNullOk =
false;
609 *se = s00 + processed;
617 bool nonNullSign =
false;
618 int nonNullDecpt = 0;
622 constexpr
int digits = std::numeric_limits<double>::max_digits10 + 1;
628 *sign = nonNullSign ? 1 : 0;
630 *decpt = nonNullDecpt;
647 else if (
length == 1 && decpt <= 0)
656 useDecimal = 1 - decpt <=
bias;
669 static constexpr
int digits(
int number)
681 template <
typename T>
689 using D = std::numeric_limits<double>;
691 constexpr
int MaxDigits = 1 + qMax(D::max_exponent10, D::digits10 - D::min_exponent10);
705 bool negative =
false;
720 total += std::max(2, digits(std::abs(decpt - 1)));
722 if (
int extraPrecision =
precision - (
length - 1); extraPrecision > 0 && !succinct)
723 total += extraPrecision;
746 constexpr
bool IsQString = std::is_same_v<T, QString>;
747 using Char = std::conditional_t<IsQString, char16_t, char>;
767 for (
int i = 0;
i < pad; ++
i)
776 int exponentDigits = digits(
exponent);
778 if (exponentDigits == 1)
787 if constexpr (IsQString)
795 auto numDecimals =
result.size() - 2 - (negative ? 1 : 0);
800 if (decpt >
view.size()) {
802 const int sign = negative ? 1 : 0;
803 while (
result.size() - sign < decpt)
small capitals from c petite p scientific f u
small capitals from c petite p scientific i
[1]
The QByteArray class provides an array of bytes.
The QChar class provides a 16-bit Unicode character.
static constexpr char32_t surrogateToUcs4(char16_t high, char16_t low) noexcept
static constexpr char16_t highSurrogate(char32_t ucs4) noexcept
static constexpr char16_t lowSurrogate(char32_t ucs4) noexcept
QVariant data(int key) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
The QString class provides a Unicode character string.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
static void DoubleToAscii(double v, DtoaMode mode, int requested_digits, char *buffer, int buffer_length, bool *sign, int *length, int *point)
double StringToDouble(const char *buffer, int length, int *processed_characters_count) const
PCRE2_SIZE PRIV() strlen(PCRE2_SPTR str)
#define QT_CLOCALE_HOLDER
bool qIsFinite(qfloat16 f) noexcept
bool qIsNaN(qfloat16 f) noexcept
QT_END_INCLUDE_NAMESPACE typedef double qreal
constexpr bool ascii_isspace(uchar c)
GLenum GLuint GLenum GLsizei length
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum format
GLenum GLint GLint * precision
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define QStringLiteral(str)
QT_BEGIN_NAMESPACE typedef char Char
QDomElement find(const QString &tagName, const QDomElement &e)