Skip to content

Commit 7e68fcd

Browse files
author
cmlchen
committed
use fpclassify to test a float number is zero or nan
1 parent 5b91551 commit 7e68fcd

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
@@ -848,8 +848,8 @@ bool Value::asBool() const {
848848
case uintValue:
849849
return value_.uint_ ? true : false;
850850
case realValue:
851-
// This is kind of strange. Not recommended.
852-
return (value_.real_ != 0.0) ? true : false;
851+
// According to JavaScript language zero or NaN is regarded as false
852+
return std::fpclassify(value_.real_) != FP_ZERO && std::fpclassify(value_.real_) != FP_NAN
853853
default:
854854
break;
855855
}

0 commit comments

Comments
 (0)