| 3458 | } |
| 3459 | |
| 3460 | float Value::asFloat() const |
| 3461 | { |
| 3462 | switch (type()) |
| 3463 | { |
| 3464 | case intValue: |
| 3465 | return static_cast<float>(value_.int_); |
| 3466 | case uintValue: |
| 3467 | #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) |
| 3468 | return static_cast<float>(value_.uint_); |
| 3469 | #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) |
| 3470 | // This can fail (silently?) if the value is bigger than MAX_FLOAT. |
| 3471 | return static_cast<float>(integerToDouble(value_.uint_)); |
| 3472 | #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) |
| 3473 | case realValue: |
| 3474 | return static_cast<float>(value_.real_); |
| 3475 | case nullValue: |
| 3476 | return 0.0; |
| 3477 | case booleanValue: |
| 3478 | return value_.bool_ ? 1.0F : 0.0F; |
| 3479 | default: |
| 3480 | break; |
| 3481 | } |
| 3482 | JSON_FAIL_MESSAGE("Value is not convertible to float."); |
| 3483 | } |
| 3484 | |
| 3485 | bool Value::asBool() const |
| 3486 | { |
no test coverage detected