Make Json::normalize more strict
Rounding a regular FP value can give an invalid result - check the result too.
This commit is contained in:
parent
2bb07fe633
commit
f5095247e8
1 changed files with 4 additions and 2 deletions
|
@ -211,11 +211,13 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero)
|
||||||
{
|
{
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
|
|
||||||
if (!std::isnormal(value)) {
|
const double value_rounded = floor(value * 100.0) / 100.0;
|
||||||
|
|
||||||
|
if (!std::isnormal(value) || !std::isnormal(value_rounded)) {
|
||||||
return zero ? Value(0.0) : Value(kNullType);
|
return zero ? Value(0.0) : Value(kNullType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Value(floor(value * 100.0) / 100.0);
|
return Value(value_rounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue