| 3240 | } |
| 3241 | |
| 3242 | bool Value::asBool() const { |
| 3243 | switch (type()) { |
| 3244 | case booleanValue: |
| 3245 | return value_.bool_; |
| 3246 | case nullValue: |
| 3247 | return false; |
| 3248 | case intValue: |
| 3249 | return value_.int_ != 0; |
| 3250 | case uintValue: |
| 3251 | return value_.uint_ != 0; |
| 3252 | case realValue: { |
| 3253 | // According to JavaScript language zero or NaN is regarded as false |
| 3254 | const auto value_classification = std::fpclassify(value_.real_); |
| 3255 | return value_classification != FP_ZERO && value_classification != FP_NAN; |
| 3256 | } |
| 3257 | default: |
| 3258 | break; |
| 3259 | } |
| 3260 | JSON_FAIL_MESSAGE("Value is not convertible to bool."); |
| 3261 | } |
| 3262 | |
| 3263 | bool Value::isConvertibleTo(ValueType other) const { |
| 3264 | switch (other) { |
no test coverage detected