From b7feb2d493eade984f097d0e42cb190db542c1d0 Mon Sep 17 00:00:00 2001 From: cmlchen Date: Fri, 21 Jun 2019 09:40:33 +0800 Subject: [PATCH] use fpclassify to test a float number is zero or nan --- src/lib_json/json_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index c0840eb..6752fa2 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -853,8 +853,8 @@ bool Value::asBool() const { case uintValue: return value_.uint_ ? true : false; case realValue: - // This is kind of strange. Not recommended. - return (value_.real_ != 0.0) ? true : false; + // According to JavaScript language zero or NaN is regarded as false + return std::fpclassify(value_.real_) != FP_ZERO && std::fpclassify(value_.real_) != FP_NAN default: break; }