Detect NaN and the infinities and return their canonical spelling.
ieee_arithmetic is deliberately not used: its availability is uneven
across the compilers PIC targets. value /= value is plain standard
Fortran and, unlike < or >, is a quiet IEEE comparison, so it does
not raise INVALID under the -ffpe-trap=invalid debug build. NaN is
therefore tested before the ordered comparisons against huge.
This is a subroutine rather than a function because a pure function may
not have an intent(out) dummy argument.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | value | |||
| character(len=:), | intent(out), | allocatable | :: | string | ||
| logical, | intent(out) | :: | special |
pure subroutine special_text(value, string, special) !! Detect NaN and the infinities and return their canonical spelling. !! !! `ieee_arithmetic` is deliberately not used: its availability is uneven !! across the compilers PIC targets. `value /= value` is plain standard !! Fortran and, unlike `<` or `>`, is a quiet IEEE comparison, so it does !! not raise INVALID under the `-ffpe-trap=invalid` debug build. NaN is !! therefore tested before the ordered comparisons against `huge`. !! !! This is a subroutine rather than a function because a pure function may !! not have an `intent(out)` dummy argument. real(dp), intent(in) :: value character(len=:), allocatable, intent(out) :: string logical, intent(out) :: special special = .true. if (value /= value) then string = PIC_FORMAT_NAN else if (value > huge(value)) then string = PIC_FORMAT_INF else if (value < -huge(value)) then string = PIC_FORMAT_NEG_INF else special = .false. string = "" end if end subroutine special_text