| 3483 | } |
| 3484 | |
| 3485 | bool Value::asBool() const |
| 3486 | { |
| 3487 | switch (type()) |
| 3488 | { |
| 3489 | case booleanValue: |
| 3490 | return value_.bool_; |
| 3491 | case nullValue: |
| 3492 | return false; |
| 3493 | case intValue: |
| 3494 | return value_.int_ != 0; |
| 3495 | case uintValue: |
| 3496 | return value_.uint_ != 0; |
| 3497 | case realValue: |
| 3498 | { |
| 3499 | // According to JavaScript language zero or NaN is regarded as false |
| 3500 | const auto value_classification = std::fpclassify(value_.real_); |
| 3501 | return value_classification != FP_ZERO && value_classification != FP_NAN; |
| 3502 | } |
| 3503 | default: |
| 3504 | break; |
| 3505 | } |
| 3506 | JSON_FAIL_MESSAGE("Value is not convertible to bool."); |
| 3507 | } |
| 3508 | |
| 3509 | bool Value::isConvertibleTo(ValueType other) const |
| 3510 | { |