| 898 | } |
| 899 | |
| 900 | bool Value::asBool() const { |
| 901 | switch (type()) { |
| 902 | case booleanValue: |
| 903 | return value_.bool_; |
| 904 | case nullValue: |
| 905 | return false; |
| 906 | case intValue: |
| 907 | return value_.int_ != 0; |
| 908 | case uintValue: |
| 909 | return value_.uint_ != 0; |
| 910 | case realValue: { |
| 911 | // According to JavaScript language zero or NaN is regarded as false |
| 912 | const auto value_classification = std::fpclassify(value_.real_); |
| 913 | return value_classification != FP_ZERO && value_classification != FP_NAN; |
| 914 | } |
| 915 | default: |
| 916 | break; |
| 917 | } |
| 918 | JSON_FAIL_MESSAGE("Value is not convertible to bool."); |
| 919 | } |
| 920 | |
| 921 | bool Value::isConvertibleTo(ValueType other) const { |
| 922 | switch (other) { |
no test coverage detected