| 802 | } |
| 803 | |
| 804 | bool Value::asBool() const { |
| 805 | switch (type()) { |
| 806 | case booleanValue: |
| 807 | return value_.bool_; |
| 808 | case nullValue: |
| 809 | return false; |
| 810 | case intValue: |
| 811 | return value_.int_ != 0; |
| 812 | case uintValue: |
| 813 | return value_.uint_ != 0; |
| 814 | case realValue: { |
| 815 | // According to JavaScript language zero or NaN is regarded as false |
| 816 | const auto value_classification = std::fpclassify(value_.real_); |
| 817 | return value_classification != FP_ZERO && value_classification != FP_NAN; |
| 818 | } |
| 819 | default: |
| 820 | break; |
| 821 | } |
| 822 | JSON_FAIL_MESSAGE("Value is not convertible to bool."); |
| 823 | } |
| 824 | |
| 825 | bool Value::isConvertibleTo(ValueType other) const { |
| 826 | switch (other) { |
no test coverage detected