Parse a character string into a single precision real.
The conversion is done in double precision and then range checked, so
a value that is finite in dp but too large for sp is reported as
an error instead of becoming infinity.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str | |||
| real(kind=sp), | intent(out) | :: | value | |||
| type(error_t), | intent(out) | :: | err |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| real(kind=dp), | private | :: | wide |
subroutine parse_real_sp_char(str, value, err) !! Parse a character string into a single precision real. !! !! The conversion is done in double precision and then range checked, so !! a value that is finite in `dp` but too large for `sp` is reported as !! an error instead of becoming infinity. character(len=*), intent(in) :: str real(sp), intent(out) :: value type(error_t), intent(out) :: err real(dp) :: wide value = 0.0_sp call parse_real_wide(str, wide, err) if (err%has_error()) return if (abs(wide) > real(huge(value), dp)) then call err%set(ERROR_PARSE, "real out of range for single precision: '"//strip(str)//"'") return end if value = real(wide, sp) end subroutine parse_real_sp_char