| 842 | } |
| 843 | |
| 844 | float Value::asFloat() const { |
| 845 | switch (type_) { |
| 846 | case intValue: |
| 847 | return static_cast<float>(value_.int_); |
| 848 | case uintValue: |
| 849 | #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) |
| 850 | return static_cast<float>(value_.uint_); |
| 851 | #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) |
| 852 | // This can fail (silently?) if the value is bigger than MAX_FLOAT. |
| 853 | return static_cast<float>(integerToDouble(value_.uint_)); |
| 854 | #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) |
| 855 | case realValue: |
| 856 | return static_cast<float>(value_.real_); |
| 857 | case nullValue: |
| 858 | return 0.0; |
| 859 | case booleanValue: |
| 860 | return value_.bool_ ? 1.0f : 0.0f; |
| 861 | default: |
| 862 | break; |
| 863 | } |
| 864 | JSON_FAIL_MESSAGE("Value is not convertible to float."); |
| 865 | } |
| 866 | |
| 867 | bool Value::asBool() const { |
| 868 | switch (type_) { |
no test coverage detected