Skip to content

Commit b7feb2d

Browse files
cmlchenbaylesj
cmlchen
authored andcommitted
use fpclassify to test a float number is zero or nan
1 parent 5510f14 commit b7feb2d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib_json/json_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,8 @@ bool Value::asBool() const {
853853
case uintValue:
854854
return value_.uint_ ? true : false;
855855
case realValue:
856-
// This is kind of strange. Not recommended.
857-
return (value_.real_ != 0.0) ? true : false;
856+
// According to JavaScript language zero or NaN is regarded as false
857+
return std::fpclassify(value_.real_) != FP_ZERO && std::fpclassify(value_.real_) != FP_NAN
858858
default:
859859
break;
860860
}

0 commit comments

Comments
 (0)