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
779a0ec7
Commit
779a0ec7
authored
May 15, 2020
by
chenguoping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
e175150f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
3 deletions
+61
-3
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+2
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+2
-1
test/src/unit-cbor.cpp
test/src/unit-cbor.cpp
+57
-1
No files found.
include/nlohmann/detail/output/binary_writer.hpp
View file @
779a0ec7
...
...
@@ -194,7 +194,8 @@ class binary_writer
}
else
{
if
(
j
.
m_value
.
number_float
<
std
::
numeric_limits
<
float
>::
max
()
and
if
(
j
.
m_value
.
number_float
>
-
std
::
numeric_limits
<
float
>::
min
()
and
j
.
m_value
.
number_float
<
std
::
numeric_limits
<
float
>::
max
()
and
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
j
.
m_value
.
number_float
)
{
oa
->
write_character
(
get_cbor_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
...
...
single_include/nlohmann/json.hpp
View file @
779a0ec7
...
...
@@ -12143,7 +12143,8 @@ class binary_writer
}
else
{
if
(
j
.
m_value
.
number_float
<
std
::
numeric_limits
<
float
>::
max
()
and
if
(
j
.
m_value
.
number_float
>
-
std
::
numeric_limits
<
float
>::
min
()
and
j
.
m_value
.
number_float
<
std
::
numeric_limits
<
float
>::
max
()
and
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
j
.
m_value
.
number_float
)
{
oa
->
write_character
(
get_cbor_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
...
...
test/src/unit-cbor.cpp
View file @
779a0ec7
...
...
@@ -834,7 +834,7 @@ TEST_CASE("CBOR")
}
}
SECTION
(
"float"
)
SECTION
(
"
double-precision
float"
)
{
SECTION
(
"3.1415925"
)
{
...
...
@@ -853,6 +853,10 @@ TEST_CASE("CBOR")
CHECK
(
json
::
from_cbor
(
result
,
true
,
false
)
==
j
);
}
}
SECTION
(
"single-precision float"
)
{
SECTION
(
"0.5"
)
{
double
v
=
0.5
;
...
...
@@ -867,6 +871,58 @@ TEST_CASE("CBOR")
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
SECTION
(
"0.0"
)
{
double
v
=
0.0
;
json
j
=
v
;
// its double-precision binary value is:
// {0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
std
::
vector
<
uint8_t
>
expected
=
{
0xfa
,
0x00
,
0x00
,
0x00
,
0x00
};
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
SECTION
(
"-0.0"
)
{
double
v
=
-
0.0
;
json
j
=
v
;
// its double-precision binary value is:
// {0xfb, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
std
::
vector
<
uint8_t
>
expected
=
{
0xfa
,
0x80
,
0x00
,
0x00
,
0x00
};
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
SECTION
(
"100.0"
)
{
double
v
=
100.0
;
json
j
=
v
;
// its double-precision binary value is:
// {0xfb, 0x40, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
std
::
vector
<
uint8_t
>
expected
=
{
0xfa
,
0x42
,
0xc8
,
0x00
,
0x00
};
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
SECTION
(
"200.0"
)
{
double
v
=
200.0
;
json
j
=
v
;
// its double-precision binary value is:
// {0xfb, 0x40, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
std
::
vector
<
uint8_t
>
expected
=
{
0xfa
,
0x43
,
0x48
,
0x00
,
0x00
};
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
v
);
}
}
SECTION
(
"half-precision float (edge cases)"
)
...
...
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