Qt 4.8
Macros | Enumerations | Functions
qlocale_tools_p.h File Reference
#include "qlocale_p.h"
#include "qstring.h"

Go to the source code of this file.

Macros

#define NEEDS_VOLATILE
 

Enumerations

enum  PrecisionMode { PMDecimalDigits = 0x01, PMSignificantDigits = 0x02, PMChopTrailingZeros = 0x03 }
 

Functions

QStringdecimalForm (QChar zero, QChar decimal, QChar group, QString &digits, int decpt, uint precision, PrecisionMode pm, bool always_show_decpt, bool thousands_group)
 
QStringexponentForm (QChar zero, QChar decimal, QChar exponential, QChar group, QChar plus, QChar minus, QString &digits, int decpt, uint precision, PrecisionMode pm, bool always_show_decpt)
 
bool isZero (double d)
 
Q_CORE_EXPORT char * qdtoa (double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **digits_str)
 
QString qlltoa (qlonglong l, int base, const QChar zero)
 
Q_CORE_EXPORT double qstrtod (const char *s00, char const **se, bool *ok)
 
qlonglong qstrtoll (const char *nptr, const char **endptr, register int base, bool *ok)
 
qulonglong qstrtoull (const char *nptr, const char **endptr, register int base, bool *ok)
 
QString qulltoa (qulonglong l, int base, const QChar _zero)
 
bool removeGroupSeparators (QLocalePrivate::CharBuff *num)
 

Macro Definition Documentation

◆ NEEDS_VOLATILE

#define NEEDS_VOLATILE

Definition at line 72 of file qlocale_tools_p.h.

Referenced by _getWord0(), _getWord1(), _setWord0(), and _setWord1().

Enumeration Type Documentation

◆ PrecisionMode

Enumerator
PMDecimalDigits 
PMSignificantDigits 
PMChopTrailingZeros 

Definition at line 80 of file qlocale_tools_p.h.

Function Documentation

◆ decimalForm()

QString& decimalForm ( QChar  zero,
QChar  decimal,
QChar  group,
QString digits,
int  decpt,
uint  precision,
PrecisionMode  pm,
bool  always_show_decpt,
bool  thousands_group 
)

Definition at line 116 of file qlocale_tools.cpp.

Referenced by QLocalePrivate::doubleToString().

121 {
122  if (decpt < 0) {
123  for (int i = 0; i < -decpt; ++i)
124  digits.prepend(zero);
125  decpt = 0;
126  }
127  else if (decpt > digits.length()) {
128  for (int i = digits.length(); i < decpt; ++i)
129  digits.append(zero);
130  }
131 
132  if (pm == PMDecimalDigits) {
133  uint decimal_digits = digits.length() - decpt;
134  for (uint i = decimal_digits; i < precision; ++i)
135  digits.append(zero);
136  }
137  else if (pm == PMSignificantDigits) {
138  for (uint i = digits.length(); i < precision; ++i)
139  digits.append(zero);
140  }
141  else { // pm == PMChopTrailingZeros
142  }
143 
144  if (always_show_decpt || decpt < digits.length())
145  digits.insert(decpt, decimal);
146 
147  if (thousands_group) {
148  for (int i = decpt - 3; i > 0; i -= 3)
149  digits.insert(i, group);
150  }
151 
152  if (decpt == 0)
153  digits.prepend(zero);
154 
155  return digits;
156 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString & prepend(QChar c)
Definition: qstring.h:261
unsigned int uint
Definition: qglobal.h:996
QString & append(QChar c)
Definition: qstring.cpp:1777
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671

◆ exponentForm()

QString& exponentForm ( QChar  zero,
QChar  decimal,
QChar  exponential,
QChar  group,
QChar  plus,
QChar  minus,
QString digits,
int  decpt,
uint  precision,
PrecisionMode  pm,
bool  always_show_decpt 
)

Definition at line 158 of file qlocale_tools.cpp.

Referenced by QLocalePrivate::doubleToString().

163 {
164  int exp = decpt - 1;
165 
166  if (pm == PMDecimalDigits) {
167  for (uint i = digits.length(); i < precision + 1; ++i)
168  digits.append(zero);
169  }
170  else if (pm == PMSignificantDigits) {
171  for (uint i = digits.length(); i < precision; ++i)
172  digits.append(zero);
173  }
174  else { // pm == PMChopTrailingZeros
175  }
176 
177  if (always_show_decpt || digits.length() > 1)
178  digits.insert(1, decimal);
179 
180  digits.append(exponential);
181  digits.append(QLocalePrivate::longLongToString(zero, group, plus, minus,
182  exp, 2, 10, -1, QLocalePrivate::AlwaysShowSign));
183 
184  return digits;
185 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static QString longLongToString(const QChar zero, const QChar group, const QChar plus, const QChar minus, qint64 l, int precision, int base, int width, unsigned flags)
Definition: qlocale.cpp:2775
unsigned int uint
Definition: qglobal.h:996
QString & append(QChar c)
Definition: qstring.cpp:1777
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671

◆ isZero()

bool isZero ( double  d)
inline

Definition at line 97 of file qlocale_tools_p.h.

Referenced by QLocalePrivate::doubleToString().

98 {
99  uchar *ch = (uchar *)&d;
100 #ifdef QT_ARMFPA
101  return !(ch[3] & 0x7F || ch[2] || ch[1] || ch[0] || ch[7] || ch[6] || ch[5] || ch[4]);
102 #else
103  if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
104  return !(ch[0] & 0x7F || ch[1] || ch[2] || ch[3] || ch[4] || ch[5] || ch[6] || ch[7]);
105  } else {
106  return !(ch[7] & 0x7F || ch[6] || ch[5] || ch[4] || ch[3] || ch[2] || ch[1] || ch[0]);
107  }
108 #endif
109 }
double d
Definition: qnumeric_p.h:62
unsigned char uchar
Definition: qglobal.h:994

◆ qdtoa()

Q_CORE_EXPORT char* qdtoa ( double  d,
int  mode,
int  ndigits,
int *  decpt,
int *  sign,
char **  rve,
char **  digits_str 
)

Definition at line 2271 of file qlocale_tools.cpp.

Referenced by isZero().

2272 {
2273  // Some values of the floating-point control word can cause _qdtoa to crash with an underflow.
2274  // We set a safe value here.
2275 #ifdef Q_OS_WIN
2276  _clear87();
2277  unsigned int oldbits = _control87(0, 0);
2278 #ifndef MCW_EM
2279 # ifdef _MCW_EM
2280 # define MCW_EM _MCW_EM
2281 # else
2282 # define MCW_EM 0x0008001F
2283 # endif
2284 #endif
2286 #endif
2287 
2288 #if defined(Q_OS_LINUX) && !defined(__UCLIBC__)
2289  fenv_t envp;
2290  feholdexcept(&envp);
2291 #endif
2292 
2293  char *s = _qdtoa(d, mode, ndigits, decpt, sign, rve, resultp);
2294 
2295 #ifdef Q_OS_WIN
2296  _clear87();
2297 #ifndef _M_X64
2298  _control87(oldbits, 0xFFFFF);
2299 #else
2300  _control87(oldbits, _MCW_EM|_MCW_DN|_MCW_RC);
2301 #endif //_M_X64
2302 #endif //Q_OS_WIN
2303 
2304 #if defined(Q_OS_LINUX) && !defined(__UCLIBC__)
2305  fesetenv(&envp);
2306 #endif
2307 
2308  return s;
2309 }
double d
Definition: qnumeric_p.h:62
#define _control87
static char * _qdtoa(NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **digits_str)
static int sign(int x)
#define MCW_EM

◆ qlltoa()

QString qlltoa ( qlonglong  l,
int  base,
const QChar  zero 
)

Definition at line 111 of file qlocale_tools.cpp.

Referenced by QLocalePrivate::longLongToString().

112 {
113  return qulltoa(l < 0 ? -l : l, base, zero);
114 }
static const uint base
Definition: qurl.cpp:268
QFactoryLoader * l
QString qulltoa(qulonglong l, int base, const QChar _zero)

◆ qstrtod()

Q_CORE_EXPORT double qstrtod ( const char *  s00,
char const **  se,
bool *  ok 
)

Definition at line 1570 of file qlocale_tools.cpp.

Referenced by isZero().

1571 {
1572  int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
1573  e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
1574  const char *s, *s0, *s1;
1575  double aadj, aadj1, adj, rv, rv0;
1576  Long L;
1577  ULong y, z;
1578  Bigint *bb1, *bd0;
1579  Bigint *bb = NULL, *bd = NULL, *bs = NULL, *delta = NULL;/* pacify gcc */
1580 
1581  /*
1582  #ifndef KR_headers
1583  const char decimal_point = localeconv()->decimal_point[0];
1584  #else
1585  const char decimal_point = '.';
1586  #endif */
1587  if (ok != 0)
1588  *ok = true;
1589 
1590  const char decimal_point = '.';
1591 
1592  sign = nz0 = nz = 0;
1593  rv = 0.;
1594 
1595 
1596  for(s = s00; isspace(uchar(*s)); s++)
1597  ;
1598 
1599  if (*s == '-') {
1600  sign = 1;
1601  s++;
1602  } else if (*s == '+') {
1603  s++;
1604  }
1605 
1606  if (*s == '\0') {
1607  s = s00;
1608  goto ret;
1609  }
1610 
1611  if (*s == '0') {
1612  nz0 = 1;
1613  while(*++s == '0') ;
1614  if (!*s)
1615  goto ret;
1616  }
1617  s0 = s;
1618  y = z = 0;
1619  for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
1620  if (nd < 9)
1621  y = 10*y + c - '0';
1622  else if (nd < 16)
1623  z = 10*z + c - '0';
1624  nd0 = nd;
1625  if (c == decimal_point) {
1626  c = *++s;
1627  if (!nd) {
1628  for(; c == '0'; c = *++s)
1629  nz++;
1630  if (c > '0' && c <= '9') {
1631  s0 = s;
1632  nf += nz;
1633  nz = 0;
1634  goto have_dig;
1635  }
1636  goto dig_done;
1637  }
1638  for(; c >= '0' && c <= '9'; c = *++s) {
1639  have_dig:
1640  nz++;
1641  if (c -= '0') {
1642  nf += nz;
1643  for(i = 1; i < nz; i++)
1644  if (nd++ < 9)
1645  y *= 10;
1646  else if (nd <= DBL_DIG + 1)
1647  z *= 10;
1648  if (nd++ < 9)
1649  y = 10*y + c;
1650  else if (nd <= DBL_DIG + 1)
1651  z = 10*z + c;
1652  nz = 0;
1653  }
1654  }
1655  }
1656  dig_done:
1657  e = 0;
1658  if (c == 'e' || c == 'E') {
1659  if (!nd && !nz && !nz0) {
1660  s = s00;
1661  goto ret;
1662  }
1663  s00 = s;
1664  esign = 0;
1665  switch(c = *++s) {
1666  case '-':
1667  esign = 1;
1668  case '+':
1669  c = *++s;
1670  }
1671  if (c >= '0' && c <= '9') {
1672  while(c == '0')
1673  c = *++s;
1674  if (c > '0' && c <= '9') {
1675  L = c - '0';
1676  s1 = s;
1677  while((c = *++s) >= '0' && c <= '9')
1678  L = 10*L + c - '0';
1679  if (s - s1 > 8 || L > 19999)
1680  /* Avoid confusion from exponents
1681  * so large that e might overflow.
1682  */
1683  e = 19999; /* safe for 16 bit ints */
1684  else
1685  e = int(L);
1686  if (esign)
1687  e = -e;
1688  }
1689  else
1690  e = 0;
1691  }
1692  else
1693  s = s00;
1694  }
1695  if (!nd) {
1696  if (!nz && !nz0)
1697  s = s00;
1698  goto ret;
1699  }
1700  e1 = e -= nf;
1701 
1702  /* Now we have nd0 digits, starting at s0, followed by a
1703  * decimal point, followed by nd-nd0 digits. The number we're
1704  * after is the integer represented by those digits times
1705  * 10**e */
1706 
1707  if (!nd0)
1708  nd0 = nd;
1709  k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
1710  rv = y;
1711  if (k > 9)
1712 #if defined(Q_OS_IRIX) && defined(Q_CC_GNU)
1713  {
1714  // work around a bug on 64 bit IRIX gcc
1715  double *t = (double *) tens;
1716  rv = t[k - 9] * rv + z;
1717  }
1718 #else
1719  rv = tens[k - 9] * rv + z;
1720 #endif
1721 
1722  bd0 = 0;
1723  if (nd <= DBL_DIG
1724 #ifndef RND_PRODQUOT
1725  && FLT_ROUNDS == 1
1726 #endif
1727  ) {
1728  if (!e)
1729  goto ret;
1730  if (e > 0) {
1731  if (e <= Ten_pmax) {
1732 #ifdef VAX
1733  goto vax_ovfl_check;
1734 #else
1735  /* rv = */ rounded_product(rv, tens[e]);
1736  goto ret;
1737 #endif
1738  }
1739  i = DBL_DIG - nd;
1740  if (e <= Ten_pmax + i) {
1741  /* A fancier test would sometimes let us do
1742  * this for larger i values.
1743  */
1744  e -= i;
1745  rv *= tens[i];
1746 #ifdef VAX
1747  /* VAX exponent range is so narrow we must
1748  * worry about overflow here...
1749  */
1750  vax_ovfl_check:
1751  setWord0(&rv, getWord0(rv) - P*Exp_msk1);
1752  /* rv = */ rounded_product(rv, tens[e]);
1753  if ((getWord0(rv) & Exp_mask)
1754  > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
1755  goto ovfl;
1756  setWord0(&rv, getWord0(rv) + P*Exp_msk1);
1757 #else
1758  /* rv = */ rounded_product(rv, tens[e]);
1759 #endif
1760  goto ret;
1761  }
1762  }
1763 #ifndef Inaccurate_Divide
1764  else if (e >= -Ten_pmax) {
1765  /* rv = */ rounded_quotient(rv, tens[-e]);
1766  goto ret;
1767  }
1768 #endif
1769  }
1770  e1 += nd - k;
1771 
1772  /* Get starting approximation = rv * 10**e1 */
1773 
1774  if (e1 > 0) {
1775  if ((i = e1 & 15) != 0)
1776  rv *= tens[i];
1777  if (e1 &= ~15) {
1778  if (e1 > DBL_MAX_10_EXP) {
1779  ovfl:
1780  // errno = ERANGE;
1781  if (ok != 0)
1782  *ok = false;
1783 #ifdef __STDC__
1784  rv = HUGE_VAL;
1785 #else
1786  /* Can't trust HUGE_VAL */
1787 #ifdef IEEE_Arith
1788  setWord0(&rv, Exp_mask);
1789  setWord1(&rv, 0);
1790 #else
1791  setWord0(&rv, Big0);
1792  setWord1(&rv, Big1);
1793 #endif
1794 #endif
1795  if (bd0)
1796  goto retfree;
1797  goto ret;
1798  }
1799  if (e1 >>= 4) {
1800  for(j = 0; e1 > 1; j++, e1 >>= 1)
1801  if (e1 & 1)
1802  rv *= bigtens[j];
1803  /* The last multiplication could overflow. */
1804  setWord0(&rv, getWord0(rv) - P*Exp_msk1);
1805  rv *= bigtens[j];
1806  if ((z = getWord0(rv) & Exp_mask)
1807  > Exp_msk1*(DBL_MAX_EXP+Bias-P))
1808  goto ovfl;
1809  if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
1810  /* set to largest number */
1811  /* (Can't trust DBL_MAX) */
1812  setWord0(&rv, Big0);
1813  setWord1(&rv, Big1);
1814  }
1815  else
1816  setWord0(&rv, getWord0(rv) + P*Exp_msk1);
1817  }
1818 
1819  }
1820  }
1821  else if (e1 < 0) {
1822  e1 = -e1;
1823  if ((i = e1 & 15) != 0)
1824  rv /= tens[i];
1825  if (e1 &= ~15) {
1826  e1 >>= 4;
1827  if (e1 >= 1 << n_bigtens)
1828  goto undfl;
1829  for(j = 0; e1 > 1; j++, e1 >>= 1)
1830  if (e1 & 1)
1831  rv *= tinytens[j];
1832  /* The last multiplication could underflow. */
1833  rv0 = rv;
1834  rv *= tinytens[j];
1835  if (rv == g_double_zero)
1836  {
1837  rv = 2.*rv0;
1838  rv *= tinytens[j];
1839  if (rv == g_double_zero)
1840  {
1841  undfl:
1842  rv = 0.;
1843  // errno = ERANGE;
1844  if (ok != 0)
1845  *ok = false;
1846  if (bd0)
1847  goto retfree;
1848  goto ret;
1849  }
1850  setWord0(&rv, Tiny0);
1851  setWord1(&rv, Tiny1);
1852  /* The refinement below will clean
1853  * this approximation up.
1854  */
1855  }
1856  }
1857  }
1858 
1859  /* Now the hard part -- adjusting rv to the correct value.*/
1860 
1861  /* Put digits into bd: true value = bd * 10^e */
1862 
1863  bd0 = s2b(s0, nd0, nd, y);
1864 
1865  for(;;) {
1866  bd = Balloc(bd0->k);
1867  Bcopy(bd, bd0);
1868  bb = d2b(rv, &bbe, &bbbits); /* rv = bb * 2^bbe */
1869  bs = i2b(1);
1870 
1871  if (e >= 0) {
1872  bb2 = bb5 = 0;
1873  bd2 = bd5 = e;
1874  }
1875  else {
1876  bb2 = bb5 = -e;
1877  bd2 = bd5 = 0;
1878  }
1879  if (bbe >= 0)
1880  bb2 += bbe;
1881  else
1882  bd2 -= bbe;
1883  bs2 = bb2;
1884 #ifdef Sudden_Underflow
1885 #ifdef IBM
1886  j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
1887 #else
1888  j = P + 1 - bbbits;
1889 #endif
1890 #else
1891  i = bbe + bbbits - 1; /* logb(rv) */
1892  if (i < Emin) /* denormal */
1893  j = bbe + (P-Emin);
1894  else
1895  j = P + 1 - bbbits;
1896 #endif
1897  bb2 += j;
1898  bd2 += j;
1899  i = bb2 < bd2 ? bb2 : bd2;
1900  if (i > bs2)
1901  i = bs2;
1902  if (i > 0) {
1903  bb2 -= i;
1904  bd2 -= i;
1905  bs2 -= i;
1906  }
1907  if (bb5 > 0) {
1908  bs = pow5mult(bs, bb5);
1909  bb1 = mult(bs, bb);
1910  Bfree(bb);
1911  bb = bb1;
1912  }
1913  if (bb2 > 0)
1914  bb = lshift(bb, bb2);
1915  if (bd5 > 0)
1916  bd = pow5mult(bd, bd5);
1917  if (bd2 > 0)
1918  bd = lshift(bd, bd2);
1919  if (bs2 > 0)
1920  bs = lshift(bs, bs2);
1921  delta = diff(bb, bd);
1922  dsign = delta->sign;
1923  delta->sign = 0;
1924  i = cmp(delta, bs);
1925  if (i < 0) {
1926  /* Error is less than half an ulp -- check for
1927  * special case of mantissa a power of two.
1928  */
1929  if (dsign || getWord1(rv) || getWord0(rv) & Bndry_mask)
1930  break;
1931  delta = lshift(delta,Log2P);
1932  if (cmp(delta, bs) > 0)
1933  goto drop_down;
1934  break;
1935  }
1936  if (i == 0) {
1937  /* exactly half-way between */
1938  if (dsign) {
1939  if ((getWord0(rv) & Bndry_mask1) == Bndry_mask1
1940  && getWord1(rv) == 0xffffffff) {
1941  /*boundary case -- increment exponent*/
1942  setWord0(&rv, (getWord0(rv) & Exp_mask)
1943  + Exp_msk1
1944 #ifdef IBM
1945  | Exp_msk1 >> 4
1946 #endif
1947  );
1948  setWord1(&rv, 0);
1949  break;
1950  }
1951  }
1952  else if (!(getWord0(rv) & Bndry_mask) && !getWord1(rv)) {
1953  drop_down:
1954  /* boundary case -- decrement exponent */
1955 #ifdef Sudden_Underflow
1956  L = getWord0(rv) & Exp_mask;
1957 #ifdef IBM
1958  if (L < Exp_msk1)
1959 #else
1960  if (L <= Exp_msk1)
1961 #endif
1962  goto undfl;
1963  L -= Exp_msk1;
1964 #else
1965  L = (getWord0(rv) & Exp_mask) - Exp_msk1;
1966 #endif
1967  setWord0(&rv, L | Bndry_mask1);
1968  setWord1(&rv, 0xffffffff);
1969 #ifdef IBM
1970  goto cont;
1971 #else
1972  break;
1973 #endif
1974  }
1975 #ifndef ROUND_BIASED
1976  if (!(getWord1(rv) & LSB))
1977  break;
1978 #endif
1979  if (dsign)
1980  rv += ulp(rv);
1981 #ifndef ROUND_BIASED
1982  else {
1983  rv -= ulp(rv);
1984 #ifndef Sudden_Underflow
1985  if (rv == g_double_zero)
1986  goto undfl;
1987 #endif
1988  }
1989 #endif
1990  break;
1991  }
1992  if ((aadj = ratio(delta, bs)) <= 2.) {
1993  if (dsign)
1994  aadj = aadj1 = 1.;
1995  else if (getWord1(rv) || getWord0(rv) & Bndry_mask) {
1996 #ifndef Sudden_Underflow
1997  if (getWord1(rv) == Tiny1 && !getWord0(rv))
1998  goto undfl;
1999 #endif
2000  aadj = 1.;
2001  aadj1 = -1.;
2002  }
2003  else {
2004  /* special case -- power of FLT_RADIX to be */
2005  /* rounded down... */
2006 
2007  if (aadj < 2./FLT_RADIX)
2008  aadj = 1./FLT_RADIX;
2009  else
2010  aadj *= 0.5;
2011  aadj1 = -aadj;
2012  }
2013  }
2014  else {
2015  aadj *= 0.5;
2016  aadj1 = dsign ? aadj : -aadj;
2017 #ifdef Check_FLT_ROUNDS
2018  switch(FLT_ROUNDS) {
2019  case 2: /* towards +infinity */
2020  aadj1 -= 0.5;
2021  break;
2022  case 0: /* towards 0 */
2023  case 3: /* towards -infinity */
2024  aadj1 += 0.5;
2025  }
2026 #else
2027  if (FLT_ROUNDS == 0)
2028  aadj1 += 0.5;
2029 #endif
2030  }
2031  y = getWord0(rv) & Exp_mask;
2032 
2033  /* Check for overflow */
2034 
2035  if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
2036  rv0 = rv;
2037  setWord0(&rv, getWord0(rv) - P*Exp_msk1);
2038  adj = aadj1 * ulp(rv);
2039  rv += adj;
2040  if ((getWord0(rv) & Exp_mask) >=
2041  Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
2042  if (getWord0(rv0) == Big0 && getWord1(rv0) == Big1)
2043  goto ovfl;
2044  setWord0(&rv, Big0);
2045  setWord1(&rv, Big1);
2046  goto cont;
2047  }
2048  else
2049  setWord0(&rv, getWord0(rv) + P*Exp_msk1);
2050  }
2051  else {
2052 #ifdef Sudden_Underflow
2053  if ((getWord0(rv) & Exp_mask) <= P*Exp_msk1) {
2054  rv0 = rv;
2055  setWord0(&rv, getWord0(rv) + P*Exp_msk1);
2056  adj = aadj1 * ulp(rv);
2057  rv += adj;
2058 #ifdef IBM
2059  if ((getWord0(rv) & Exp_mask) < P*Exp_msk1)
2060 #else
2061  if ((getWord0(rv) & Exp_mask) <= P*Exp_msk1)
2062 #endif
2063  {
2064  if (getWord0(rv0) == Tiny0
2065  && getWord1(rv0) == Tiny1)
2066  goto undfl;
2067  setWord0(&rv, Tiny0);
2068  setWord1(&rv, Tiny1);
2069  goto cont;
2070  }
2071  else
2072  setWord0(&rv, getWord0(rv) - P*Exp_msk1);
2073  }
2074  else {
2075  adj = aadj1 * ulp(rv);
2076  rv += adj;
2077  }
2078 #else
2079  /* Compute adj so that the IEEE rounding rules will
2080  * correctly round rv + adj in some half-way cases.
2081  * If rv * ulp(rv) is denormalized (i.e.,
2082  * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
2083  * trouble from bits lost to denormalization;
2084  * example: 1.2e-307 .
2085  */
2086  if (y <= (P-1)*Exp_msk1 && aadj >= 1.) {
2087  aadj1 = int(aadj + 0.5);
2088  if (!dsign)
2089  aadj1 = -aadj1;
2090  }
2091  adj = aadj1 * ulp(rv);
2092  rv += adj;
2093 #endif
2094  }
2095  z = getWord0(rv) & Exp_mask;
2096  if (y == z) {
2097  /* Can we stop now? */
2098  L = Long(aadj);
2099  aadj -= L;
2100  /* The tolerances below are conservative. */
2101  if (dsign || getWord1(rv) || getWord0(rv) & Bndry_mask) {
2102  if (aadj < .4999999 || aadj > .5000001)
2103  break;
2104  }
2105  else if (aadj < .4999999/FLT_RADIX)
2106  break;
2107  }
2108  cont:
2109  Bfree(bb);
2110  Bfree(bd);
2111  Bfree(bs);
2112  Bfree(delta);
2113  }
2114  retfree:
2115  Bfree(bb);
2116  Bfree(bd);
2117  Bfree(bs);
2118  Bfree(bd0);
2119  Bfree(delta);
2120  ret:
2121  if (se)
2122  *se = s;
2123  return sign ? -rv : rv;
2124 }
#define Big1
#define Emin
#define Big0
#define rounded_product(a, b)
unsigned char c[8]
Definition: qnumeric_p.h:62
#define DBL_DIG
Definition: qvariant.cpp:69
#define Bndry_mask1
static Bigint * d2b(double d, int *e, int *bits)
#define LSB
static ULong getWord1(const NEEDS_VOLATILE double x)
static Bigint * i2b(int i)
static Bigint * lshift(Bigint *b, int k)
static double ratio(Bigint *a, Bigint *b)
#define ULong
static int sign(int x)
#define Tiny0
unsigned char uchar
Definition: qglobal.h:994
static const double tens[]
static Bigint * mult(Bigint *a, Bigint *b)
#define Ten_pmax
static Bigint * diff(Bigint *a, Bigint *b)
#define n_bigtens
static Bigint * Balloc(int k)
#define Bcopy(x, y)
#define Exp_msk1
#define Exp_mask
static const double bigtens[]
static ULong getWord0(const NEEDS_VOLATILE double x)
#define Bndry_mask
#define Bias
#define rounded_quotient(a, b)
static void setWord1(NEEDS_VOLATILE double *x, ULong l)
static void setWord0(NEEDS_VOLATILE double *x, ULong l)
static Bigint * pow5mult(Bigint *b, int k)
#define Log2P
static void Bfree(Bigint *v)
static Bigint * s2b(const char *s, int nd0, int nd, ULong y9)
#define Long
#define Tiny1
static const double tinytens[]
static int cmp(Bigint *a, Bigint *b)
#define P
static double g_double_zero
static double ulp(double x)

◆ qstrtoll()

qlonglong qstrtoll ( const char *  nptr,
const char **  endptr,
register int  base,
bool *  ok 
)

Definition at line 391 of file qlocale_tools.cpp.

Referenced by QLocalePrivate::bytearrayToLongLong(), getWinLocaleName(), and isZero().

392 {
393  register const char *s;
394  register qulonglong acc;
395  register unsigned char c;
396  register qulonglong qbase, cutoff;
397  register int neg, any, cutlim;
398 
399  /*
400  * Skip white space and pick up leading +/- sign if any.
401  * If base is 0, allow 0x for hex and 0 for octal, else
402  * assume decimal; if base is already 16, allow 0x.
403  */
404  s = nptr;
405  do {
406  c = *s++;
407  } while (isspace(c));
408  if (c == '-') {
409  neg = 1;
410  c = *s++;
411  } else {
412  neg = 0;
413  if (c == '+')
414  c = *s++;
415  }
416  if ((base == 0 || base == 16) &&
417  c == '0' && (*s == 'x' || *s == 'X')) {
418  c = s[1];
419  s += 2;
420  base = 16;
421  }
422  if (base == 0)
423  base = c == '0' ? 8 : 10;
424 
425  /*
426  * Compute the cutoff value between legal numbers and illegal
427  * numbers. That is the largest legal value, divided by the
428  * base. An input number that is greater than this value, if
429  * followed by a legal input character, is too big. One that
430  * is equal to this value may be valid or not; the limit
431  * between valid and invalid numbers is then based on the last
432  * digit. For instance, if the range for quads is
433  * [-9223372036854775808..9223372036854775807] and the input base
434  * is 10, cutoff will be set to 922337203685477580 and cutlim to
435  * either 7 (neg==0) or 8 (neg==1), meaning that if we have
436  * accumulated a value > 922337203685477580, or equal but the
437  * next digit is > 7 (or 8), the number is too big, and we will
438  * return a range error.
439  *
440  * Set any if any `digits' consumed; make it negative to indicate
441  * overflow.
442  */
443  qbase = unsigned(base);
444  cutoff = neg ? qulonglong(0-(LLONG_MIN + LLONG_MAX)) + LLONG_MAX : LLONG_MAX;
445  cutlim = cutoff % qbase;
446  cutoff /= qbase;
447  for (acc = 0, any = 0;; c = *s++) {
448  if (!isascii(c))
449  break;
450  if (isdigit(c))
451  c -= '0';
452  else if (isalpha(c))
453  c -= isupper(c) ? 'A' - 10 : 'a' - 10;
454  else
455  break;
456  if (c >= base)
457  break;
458  if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
459  any = -1;
460  else {
461  any = 1;
462  acc *= qbase;
463  acc += c;
464  }
465  }
466  if (any < 0) {
467  acc = neg ? LLONG_MIN : LLONG_MAX;
468  if (ok != 0)
469  *ok = false;
470  } else if (neg) {
471  acc = (~acc) + 1;
472  }
473  if (endptr != 0)
474  *endptr = (any >= 0 ? s - 1 : nptr);
475 
476  if (ok != 0)
477  *ok = any > 0;
478 
479  return acc;
480 }
unsigned char c[8]
Definition: qnumeric_p.h:62
#define LLONG_MAX
static const uint base
Definition: qurl.cpp:268
#define LLONG_MIN
quint64 qulonglong
Definition: qglobal.h:952

◆ qstrtoull()

qulonglong qstrtoull ( const char *  nptr,
const char **  endptr,
register int  base,
bool *  ok 
)

Definition at line 310 of file qlocale_tools.cpp.

Referenced by QLocalePrivate::bytearrayToUnsLongLong(), isZero(), and winIso639LangName().

311 {
312  register const char *s = nptr;
313  register qulonglong acc;
314  register unsigned char c;
315  register qulonglong qbase, cutoff;
316  register int any, cutlim;
317 
318  if (ok != 0)
319  *ok = true;
320 
321  /*
322  * See strtoq for comments as to the logic used.
323  */
324  s = nptr;
325  do {
326  c = *s++;
327  } while (isspace(c));
328  if (c == '-') {
329  if (ok != 0)
330  *ok = false;
331  if (endptr != 0)
332  *endptr = s - 1;
333  return 0;
334  } else {
335  if (c == '+')
336  c = *s++;
337  }
338  if ((base == 0 || base == 16) &&
339  c == '0' && (*s == 'x' || *s == 'X')) {
340  c = s[1];
341  s += 2;
342  base = 16;
343  }
344  if (base == 0)
345  base = c == '0' ? 8 : 10;
346  qbase = unsigned(base);
347  cutoff = qulonglong(ULLONG_MAX) / qbase;
348  cutlim = qulonglong(ULLONG_MAX) % qbase;
349  for (acc = 0, any = 0;; c = *s++) {
350  if (!isascii(c))
351  break;
352  if (isdigit(c))
353  c -= '0';
354  else if (isalpha(c))
355  c -= isupper(c) ? 'A' - 10 : 'a' - 10;
356  else
357  break;
358  if (c >= base)
359  break;
360  if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
361  any = -1;
362  else {
363  any = 1;
364  acc *= qbase;
365  acc += c;
366  }
367  }
368  if (any == 0) {
369  if (ok != 0)
370  *ok = false;
371  } else if (any < 0) {
372  acc = ULLONG_MAX;
373  if (ok != 0)
374  *ok = false;
375  }
376  if (endptr != 0)
377  *endptr = (any ? s - 1 : nptr);
378  return acc;
379 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static const uint base
Definition: qurl.cpp:268
#define ULLONG_MAX
quint64 qulonglong
Definition: qglobal.h:952

◆ qulltoa()

QString qulltoa ( qulonglong  l,
int  base,
const QChar  _zero 
)

Definition at line 79 of file qlocale_tools.cpp.

Referenced by QLocalePrivate::longLongToString(), qlltoa(), and QLocalePrivate::unsLongLongToString().

80 {
81  ushort buff[65]; // length of MAX_ULLONG in base 2
82  ushort *p = buff + 65;
83 
84  if (base != 10 || _zero.unicode() == '0') {
85  while (l != 0) {
86  int c = l % base;
87 
88  --p;
89 
90  if (c < 10)
91  *p = '0' + c;
92  else
93  *p = c - 10 + 'a';
94 
95  l /= base;
96  }
97  }
98  else {
99  while (l != 0) {
100  int c = l % base;
101 
102  *(--p) = _zero.unicode() + c;
103 
104  l /= base;
105  }
106  }
107 
108  return QString(reinterpret_cast<QChar *>(p), 65 - (p - buff));
109 }
unsigned char c[8]
Definition: qnumeric_p.h:62
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const uint base
Definition: qurl.cpp:268
unsigned short ushort
Definition: qglobal.h:995
QFactoryLoader * l

◆ removeGroupSeparators()

bool removeGroupSeparators ( QLocalePrivate::CharBuff num)

Definition at line 188 of file qlocale_tools.cpp.

Referenced by isZero(), and QLocalePrivate::numberToCLocale().

189 {
190  int group_cnt = 0; // counts number of group chars
191  int decpt_idx = -1;
192 
193  char *data = num->data();
194  int l = qstrlen(data);
195 
196  // Find the decimal point and check if there are any group chars
197  int i = 0;
198  for (; i < l; ++i) {
199  char c = data[i];
200 
201  if (c == ',') {
202  if (i == 0 || data[i - 1] < '0' || data[i - 1] > '9')
203  return false;
204  if (i == l - 1 || data[i + 1] < '0' || data[i + 1] > '9')
205  return false;
206  ++group_cnt;
207  }
208  else if (c == '.') {
209  // Fail if more than one decimal points
210  if (decpt_idx != -1)
211  return false;
212  decpt_idx = i;
213  } else if (c == 'e' || c == 'E') {
214  // an 'e' or 'E' - if we have not encountered a decimal
215  // point, this is where it "is".
216  if (decpt_idx == -1)
217  decpt_idx = i;
218  }
219  }
220 
221  // If no group chars, we're done
222  if (group_cnt == 0)
223  return true;
224 
225  // No decimal point means that it "is" at the end of the string
226  if (decpt_idx == -1)
227  decpt_idx = l;
228 
229  i = 0;
230  while (i < l && group_cnt > 0) {
231  char c = data[i];
232 
233  if (c == ',') {
234  // Don't allow group chars after the decimal point
235  if (i > decpt_idx)
236  return false;
237 
238  // Check that it is placed correctly relative to the decpt
239  if ((decpt_idx - i) % 4 != 0)
240  return false;
241 
242  // Remove it
243  memmove(data + i, data + i + 1, l - i - 1);
244  data[--l] = '\0';
245 
246  --group_cnt;
247  --decpt_idx;
248  } else {
249  // Check that we are not missing a separator
250  if (i < decpt_idx
251  && (decpt_idx - i) % 4 == 0
252  && !(i == 0 && c == '-')) // check for negative sign at start of string
253  return false;
254  ++i;
255  }
256  }
257 
258  return true;
259 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static const char * data(const QByteArray &arr)
uint qstrlen(const char *str)
Definition: qbytearray.h:79
QFactoryLoader * l