Use "shortest" double conversion for JSON
Task-number: QTBUG-42419 Change-Id: I649c4de96a2e41078e139c0f382e5a6cf96d3bb9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
15b5b3b3f0
commit
573f87d813
@ -32,6 +32,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qlocale.h>
|
||||
#include "qjsonwriter_p.h"
|
||||
#include "qjson_p.h"
|
||||
#include "private/qutfcodec_p.h"
|
||||
@ -123,7 +124,7 @@ static void valueToJson(const QJsonPrivate::Base *b, const QJsonPrivate::Value &
|
||||
case QJsonValue::Double: {
|
||||
const double d = v.toDouble(b);
|
||||
if (qIsFinite(d)) // +2 to format to ensure the expected precision
|
||||
json += QByteArray::number(d, 'g', std::numeric_limits<double>::digits10 + 2); // ::digits10 is 15
|
||||
json += QByteArray::number(d, 'g', QLocale::FloatingPointShortest);
|
||||
else
|
||||
json += "null"; // +INF || -INF || NaN (see RFC4627#section2.4)
|
||||
break;
|
||||
|
@ -6,4 +6,8 @@ CONFIG += testcase
|
||||
!android:TESTDATA += bom.json test.json test.bjson test3.json test2.json
|
||||
else:RESOURCES += json.qrc
|
||||
|
||||
!contains(QT_CONFIG, doubleconversion):!contains(QT_CONFIG, system-doubleconversion) {
|
||||
DEFINES += QT_NO_DOUBLECONVERSION
|
||||
}
|
||||
|
||||
SOURCES += tst_qtjson.cpp
|
||||
|
@ -1408,9 +1408,7 @@ void tst_QtJson::toJsonLargeNumericValues()
|
||||
" \"Array\": [\n"
|
||||
" 1.234567,\n"
|
||||
" 1.7976931348623157e+308,\n"
|
||||
// ((4.9406564584124654e-324 == 5e-324) == true)
|
||||
// I can only think JavaScript has a special formatter to
|
||||
// emit this value for this IEEE754 bit pattern.
|
||||
#ifdef QT_NO_DOUBLECONVERSION // "shortest" double conversion is not very short then
|
||||
" 4.9406564584124654e-324,\n"
|
||||
" 2.2250738585072014e-308,\n"
|
||||
" 1.7976931348623157e+308,\n"
|
||||
@ -1421,6 +1419,18 @@ void tst_QtJson::toJsonLargeNumericValues()
|
||||
" -1.7976931348623157e+308,\n"
|
||||
" -2.2204460492503131e-16,\n"
|
||||
" -4.9406564584124654e-324,\n"
|
||||
#else
|
||||
" 5e-324,\n"
|
||||
" 2.2250738585072014e-308,\n"
|
||||
" 1.7976931348623157e+308,\n"
|
||||
" 2.220446049250313e-16,\n"
|
||||
" 5e-324,\n"
|
||||
" 0,\n"
|
||||
" -2.2250738585072014e-308,\n"
|
||||
" -1.7976931348623157e+308,\n"
|
||||
" -2.220446049250313e-16,\n"
|
||||
" -5e-324,\n"
|
||||
#endif
|
||||
" 0,\n"
|
||||
" 9007199254740992,\n"
|
||||
" -9007199254740992\n"
|
||||
|
Loading…
Reference in New Issue
Block a user