Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
3cca6308
Unverified
Commit
3cca6308
authored
Jan 21, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
cleanup after #915
parent
010e5960
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
495 additions
and
359 deletions
+495
-359
Makefile
Makefile
+1
-0
README.md
README.md
+1
-2
develop/detail/conversions/to_chars.hpp
develop/detail/conversions/to_chars.hpp
+231
-165
develop/detail/serializer.hpp
develop/detail/serializer.hpp
+2
-2
src/json.hpp
src/json.hpp
+233
-167
test/src/unit-to_chars.cpp
test/src/unit-to_chars.cpp
+27
-23
No files found.
Makefile
View file @
3cca6308
...
@@ -8,6 +8,7 @@ SRCS = develop/json.hpp \
...
@@ -8,6 +8,7 @@ SRCS = develop/json.hpp \
develop/detail/exceptions.hpp
\
develop/detail/exceptions.hpp
\
develop/detail/value_t.hpp
\
develop/detail/value_t.hpp
\
develop/detail/conversions/from_json.hpp
\
develop/detail/conversions/from_json.hpp
\
develop/detail/conversions/to_chars.hpp
\
develop/detail/conversions/to_json.hpp
\
develop/detail/conversions/to_json.hpp
\
develop/detail/parsing/input_adapters.hpp
\
develop/detail/parsing/input_adapters.hpp
\
develop/detail/parsing/lexer.hpp
\
develop/detail/parsing/lexer.hpp
\
...
...
README.md
View file @
3cca6308
...
@@ -821,8 +821,6 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
...
@@ -821,8 +821,6 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
The class contains the UTF-8 Decoder from Bjoern Hoehrmann which is licensed under the
[
MIT License
](
http://opensource.org/licenses/MIT
)
(
see
above). Copyright
©
2008-2009
[
Björn Hoehrmann
](
http://bjoern.hoehrmann.de/
)
<bjoern@hoehrmann.de>
The class contains the UTF-8 Decoder from Bjoern Hoehrmann which is licensed under the
[
MIT License
](
http://opensource.org/licenses/MIT
)
(
see
above). Copyright
©
2008-2009
[
Björn Hoehrmann
](
http://bjoern.hoehrmann.de/
)
<bjoern@hoehrmann.de>
* * *
The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the
[
MIT License
](
http://opensource.org/licenses/MIT
)
(
see
above). Copyright
©
2009
[
Florian Loitsch
](
http://florian.loitsch.com/
)
The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the
[
MIT License
](
http://opensource.org/licenses/MIT
)
(
see
above). Copyright
©
2009
[
Florian Loitsch
](
http://florian.loitsch.com/
)
## Contact
## Contact
...
@@ -934,6 +932,7 @@ I deeply appreciate the help of the following people.
...
@@ -934,6 +932,7 @@ I deeply appreciate the help of the following people.
-
[
Matthias Möller
](
https://github.com/TinyTinni
)
added a
`.natvis`
for the MSVC debug view.
-
[
Matthias Möller
](
https://github.com/TinyTinni
)
added a
`.natvis`
for the MSVC debug view.
-
[
bogemic
](
https://github.com/bogemic
)
fixed some C++17 deprecation warnings.
-
[
bogemic
](
https://github.com/bogemic
)
fixed some C++17 deprecation warnings.
-
[
Eren Okka
](
https://github.com/erengy
)
fixed some MSVC warnings.
-
[
Eren Okka
](
https://github.com/erengy
)
fixed some MSVC warnings.
-
[
abolz
](
https://github.com/abolz
)
integrated the Grisu2 algorithm for proper floating-point formatting, allowing more roundtrip checks to succeed.
Thanks a lot for helping out! Please
[
let me know
](
mailto:mail@nlohmann.me
)
if I forgot someone.
Thanks a lot for helping out! Please
[
let me know
](
mailto:mail@nlohmann.me
)
if I forgot someone.
...
...
develop/detail/conversions/to_chars.hpp
View file @
3cca6308
This diff is collapsed.
Click to expand it.
develop/detail/serializer.hpp
View file @
3cca6308
...
@@ -483,8 +483,8 @@ class serializer
...
@@ -483,8 +483,8 @@ class serializer
}
}
// If number_float_t is an IEEE-754 single or double precision number,
// If number_float_t is an IEEE-754 single or double precision number,
// use the Grisu2 algorithm to produce short numbers which are
guaranteed
// use the Grisu2 algorithm to produce short numbers which are
// to round-trip, using strtof and strtod, resp.
//
guaranteed
to round-trip, using strtof and strtod, resp.
//
//
// NB: The test below works if <long double> == <double>.
// NB: The test below works if <long double> == <double>.
static
constexpr
bool
is_ieee_single_or_double
static
constexpr
bool
is_ieee_single_or_double
...
...
src/json.hpp
View file @
3cca6308
This diff is collapsed.
Click to expand it.
test/src/unit-to_chars.cpp
View file @
3cca6308
...
@@ -60,26 +60,28 @@ static float make_float(uint64_t f, int e)
...
@@ -60,26 +60,28 @@ static float make_float(uint64_t f, int e)
constexpr
int
kDenormalExponent
=
1
-
kExponentBias
;
constexpr
int
kDenormalExponent
=
1
-
kExponentBias
;
constexpr
int
kMaxExponent
=
0xFF
-
kExponentBias
;
constexpr
int
kMaxExponent
=
0xFF
-
kExponentBias
;
while
(
f
>
kHiddenBit
+
kSignificandMask
)
{
while
(
f
>
kHiddenBit
+
kSignificandMask
)
{
f
>>=
1
;
f
>>=
1
;
e
++
;
e
++
;
}
}
if
(
e
>=
kMaxExponent
)
{
if
(
e
>=
kMaxExponent
)
{
return
std
::
numeric_limits
<
float
>::
infinity
();
return
std
::
numeric_limits
<
float
>::
infinity
();
}
}
if
(
e
<
kDenormalExponent
)
{
if
(
e
<
kDenormalExponent
)
{
return
0.0
;
return
0.0
;
}
}
while
(
e
>
kDenormalExponent
&&
(
f
&
kHiddenBit
)
==
0
)
{
while
(
e
>
kDenormalExponent
&&
(
f
&
kHiddenBit
)
==
0
)
{
f
<<=
1
;
f
<<=
1
;
e
--
;
e
--
;
}
}
uint64_t
biased_exponent
;
uint64_t
biased_exponent
=
(
e
==
kDenormalExponent
&&
(
f
&
kHiddenBit
)
==
0
)
if
(
e
==
kDenormalExponent
&&
(
f
&
kHiddenBit
)
==
0
)
?
0
biased_exponent
=
0
;
:
static_cast
<
uint64_t
>
(
e
+
kExponentBias
);
else
biased_exponent
=
static_cast
<
uint64_t
>
(
e
+
kExponentBias
);
uint64_t
bits
=
(
f
&
kSignificandMask
)
|
(
biased_exponent
<<
kPhysicalSignificandSize
);
uint64_t
bits
=
(
f
&
kSignificandMask
)
|
(
biased_exponent
<<
kPhysicalSignificandSize
);
return
reinterpret_bits
<
float
>
(
static_cast
<
uint32_t
>
(
bits
));
return
reinterpret_bits
<
float
>
(
static_cast
<
uint32_t
>
(
bits
));
...
@@ -110,26 +112,28 @@ static double make_double(uint64_t f, int e)
...
@@ -110,26 +112,28 @@ static double make_double(uint64_t f, int e)
constexpr
int
kDenormalExponent
=
1
-
kExponentBias
;
constexpr
int
kDenormalExponent
=
1
-
kExponentBias
;
constexpr
int
kMaxExponent
=
0x7FF
-
kExponentBias
;
constexpr
int
kMaxExponent
=
0x7FF
-
kExponentBias
;
while
(
f
>
kHiddenBit
+
kSignificandMask
)
{
while
(
f
>
kHiddenBit
+
kSignificandMask
)
{
f
>>=
1
;
f
>>=
1
;
e
++
;
e
++
;
}
}
if
(
e
>=
kMaxExponent
)
{
if
(
e
>=
kMaxExponent
)
{
return
std
::
numeric_limits
<
double
>::
infinity
();
return
std
::
numeric_limits
<
double
>::
infinity
();
}
}
if
(
e
<
kDenormalExponent
)
{
if
(
e
<
kDenormalExponent
)
{
return
0.0
;
return
0.0
;
}
}
while
(
e
>
kDenormalExponent
&&
(
f
&
kHiddenBit
)
==
0
)
{
while
(
e
>
kDenormalExponent
&&
(
f
&
kHiddenBit
)
==
0
)
{
f
<<=
1
;
f
<<=
1
;
e
--
;
e
--
;
}
}
uint64_t
biased_exponent
;
uint64_t
biased_exponent
=
(
e
==
kDenormalExponent
&&
(
f
&
kHiddenBit
)
==
0
)
if
(
e
==
kDenormalExponent
&&
(
f
&
kHiddenBit
)
==
0
)
?
0
biased_exponent
=
0
;
:
static_cast
<
uint64_t
>
(
e
+
kExponentBias
);
else
biased_exponent
=
static_cast
<
uint64_t
>
(
e
+
kExponentBias
);
uint64_t
bits
=
(
f
&
kSignificandMask
)
|
(
biased_exponent
<<
kPhysicalSignificandSize
);
uint64_t
bits
=
(
f
&
kSignificandMask
)
|
(
biased_exponent
<<
kPhysicalSignificandSize
);
return
reinterpret_bits
<
double
>
(
bits
);
return
reinterpret_bits
<
double
>
(
bits
);
...
@@ -139,7 +143,7 @@ TEST_CASE("digit gen")
...
@@ -139,7 +143,7 @@ TEST_CASE("digit gen")
{
{
SECTION
(
"single precision"
)
SECTION
(
"single precision"
)
{
{
auto
check_float
=
[](
float
number
,
const
std
::
string
&
digits
,
int
expected_exponent
)
auto
check_float
=
[](
float
number
,
const
std
::
string
&
digits
,
int
expected_exponent
)
{
{
CAPTURE
(
number
);
CAPTURE
(
number
);
CAPTURE
(
digits
);
CAPTURE
(
digits
);
...
@@ -203,7 +207,7 @@ TEST_CASE("digit gen")
...
@@ -203,7 +207,7 @@ TEST_CASE("digit gen")
SECTION
(
"double precision"
)
SECTION
(
"double precision"
)
{
{
auto
check_double
=
[](
double
number
,
const
std
::
string
&
digits
,
int
expected_exponent
)
auto
check_double
=
[](
double
number
,
const
std
::
string
&
digits
,
int
expected_exponent
)
{
{
CAPTURE
(
number
);
CAPTURE
(
number
);
CAPTURE
(
digits
);
CAPTURE
(
digits
);
...
@@ -349,7 +353,7 @@ TEST_CASE("formatting")
...
@@ -349,7 +353,7 @@ TEST_CASE("formatting")
{
{
SECTION
(
"single precision"
)
SECTION
(
"single precision"
)
{
{
auto
check_float
=
[](
float
number
,
const
std
::
string
&
expected
)
auto
check_float
=
[](
float
number
,
const
std
::
string
&
expected
)
{
{
char
buf
[
32
];
char
buf
[
32
];
char
*
end
=
nlohmann
::
detail
::
to_chars
(
buf
,
buf
+
32
,
number
);
char
*
end
=
nlohmann
::
detail
::
to_chars
(
buf
,
buf
+
32
,
number
);
...
@@ -357,7 +361,7 @@ TEST_CASE("formatting")
...
@@ -357,7 +361,7 @@ TEST_CASE("formatting")
CHECK
(
actual
==
expected
);
CHECK
(
actual
==
expected
);
};
};
// %.9g
// %.9g
check_float
(
-
1.2345e-22
f
,
"-1.2345e-22"
);
// -1.23450004e-22
check_float
(
-
1.2345e-22
f
,
"-1.2345e-22"
);
// -1.23450004e-22
check_float
(
-
1.2345e-21
f
,
"-1.2345e-21"
);
// -1.23450002e-21
check_float
(
-
1.2345e-21
f
,
"-1.2345e-21"
);
// -1.23450002e-21
check_float
(
-
1.2345e-20
f
,
"-1.2345e-20"
);
// -1.23450002e-20
check_float
(
-
1.2345e-20
f
,
"-1.2345e-20"
);
// -1.23450002e-20
...
@@ -409,7 +413,7 @@ TEST_CASE("formatting")
...
@@ -409,7 +413,7 @@ TEST_CASE("formatting")
SECTION
(
"double precision"
)
SECTION
(
"double precision"
)
{
{
auto
check_double
=
[](
double
number
,
const
std
::
string
&
expected
)
auto
check_double
=
[](
double
number
,
const
std
::
string
&
expected
)
{
{
char
buf
[
32
];
char
buf
[
32
];
char
*
end
=
nlohmann
::
detail
::
to_chars
(
buf
,
buf
+
32
,
number
);
char
*
end
=
nlohmann
::
detail
::
to_chars
(
buf
,
buf
+
32
,
number
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment