special_text Subroutine

private 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.

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: value
character(len=:), intent(out), allocatable :: string
logical, intent(out) :: special

Called by

proc~~special_text~~CalledByGraph proc~special_text special_text proc~to_string_fixed_dp to_string_fixed_dp proc~to_string_fixed_dp->proc~special_text proc~to_string_sci_dp to_string_sci_dp proc~to_string_sci_dp->proc~special_text interface~to_string_fixed to_string_fixed interface~to_string_fixed->proc~to_string_fixed_dp proc~to_string_fixed_sp to_string_fixed_sp interface~to_string_fixed->proc~to_string_fixed_sp interface~to_string_sci to_string_sci interface~to_string_sci->proc~to_string_sci_dp proc~to_string_sci_sp to_string_sci_sp interface~to_string_sci->proc~to_string_sci_sp proc~to_string_fixed_sp->proc~to_string_fixed_dp proc~to_string_sci_sp->proc~to_string_sci_dp

Source Code

   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