Json writer, support larger signed integers upto 2^53
Previously only 32bit signed integers were ensured to be supported by JsonValue type via API but it is expected that a larger integer range should be supported by a JSON implementation. This commit brings the Qt implementation into parity with NodeJS JSON.stringify() in respect of the JavaScript Number type. Change-Id: If91153cb3b13ecc14c50da97055b35ce42f341e7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
6348de8737
commit
5f9d58848a
@ -155,6 +155,18 @@ QJsonValue::QJsonValue(int n)
|
||||
this->dbl = n;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
Creates a value of type Double, with value \a n.
|
||||
NOTE: the integer limits for IEEE 754 double precision data is 2^53 (-9007199254740992 to +9007199254740992).
|
||||
If you pass in values outside this range expect a loss of precision to occur.
|
||||
*/
|
||||
QJsonValue::QJsonValue(qint64 n)
|
||||
: d(0), t(Double)
|
||||
{
|
||||
this->dbl = n;
|
||||
}
|
||||
|
||||
/*!
|
||||
Creates a value of type String, with value \a s.
|
||||
*/
|
||||
|
@ -79,6 +79,7 @@ public:
|
||||
QJsonValue(bool b);
|
||||
QJsonValue(double n);
|
||||
QJsonValue(int n);
|
||||
QJsonValue(qint64 n);
|
||||
QJsonValue(const QString &s);
|
||||
QJsonValue(QLatin1String s);
|
||||
QJsonValue(const QJsonArray &a);
|
||||
|
@ -1128,6 +1128,8 @@ void tst_QtJson::toJsonLargeNumericValues()
|
||||
array.append(QJsonValue(-std::numeric_limits<double>::epsilon()));
|
||||
array.append(QJsonValue(-std::numeric_limits<double>::denorm_min()));
|
||||
array.append(QJsonValue(-0.0));
|
||||
array.append(QJsonValue(9007199254740992LL)); // JS Number max integer
|
||||
array.append(QJsonValue(-9007199254740992LL)); // JS Number min integer
|
||||
object.insert("Array", array);
|
||||
|
||||
QByteArray json = QJsonDocument(object).toJson();
|
||||
@ -1150,7 +1152,9 @@ void tst_QtJson::toJsonLargeNumericValues()
|
||||
" -1.7976931348623157e+308,\n"
|
||||
" -2.2204460492503131e-16,\n"
|
||||
" -4.9406564584124654e-324,\n"
|
||||
" 0\n"
|
||||
" 0,\n"
|
||||
" 9007199254740992,\n"
|
||||
" -9007199254740992\n"
|
||||
" ]\n"
|
||||
"}\n";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user