to_string_fixed_dp Function

private pure function to_string_fixed_dp(value, decimals) result(string)

Fixed point rendering of a real(dp) value.

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: value
integer(kind=default_int), intent(in) :: decimals

Return Value character(len=:), allocatable


Calls

proc~~to_string_fixed_dp~~CallsGraph proc~to_string_fixed_dp to_string_fixed_dp proc~assemble_fixed assemble_fixed proc~to_string_fixed_dp->proc~assemble_fixed proc~expand_exact expand_exact proc~to_string_fixed_dp->proc~expand_exact proc~is_negative is_negative proc~to_string_fixed_dp->proc~is_negative proc~round_decimal round_decimal proc~to_string_fixed_dp->proc~round_decimal proc~special_text special_text proc~to_string_fixed_dp->proc~special_text proc~bd_mul_pow bd_mul_pow proc~expand_exact->proc~bd_mul_pow proc~bd_set bd_set proc~expand_exact->proc~bd_set proc~bd_to_digits bd_to_digits proc~expand_exact->proc~bd_to_digits proc~increment_digits increment_digits proc~round_decimal->proc~increment_digits proc~bd_mul_small bd_mul_small proc~bd_mul_pow->proc~bd_mul_small proc~limb_to_digits limb_to_digits proc~bd_to_digits->proc~limb_to_digits

Called by

proc~~to_string_fixed_dp~~CalledByGraph proc~to_string_fixed_dp to_string_fixed_dp 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 proc~to_string_fixed_sp->proc~to_string_fixed_dp

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: bump
integer(kind=default_int), private :: dec
character(len=WORK_LEN), private :: exact
integer(kind=default_int), private :: n_exact
integer(kind=default_int), private :: n_keep
integer(kind=default_int), private :: n_rounded
logical, private :: negative
integer(kind=default_int), private :: point_pos
character(len=WORK_LEN), private :: rounded
logical, private :: special

Source Code

   pure function to_string_fixed_dp(value, decimals) result(string)
      !! Fixed point rendering of a `real(dp)` value.
      real(dp), intent(in) :: value
      integer(default_int), intent(in) :: decimals
      character(len=:), allocatable :: string

      character(len=WORK_LEN) :: exact, rounded
      integer(default_int) :: n_exact, point_pos, dec, n_keep, n_rounded, bump
      logical :: negative, special

      call special_text(value, string, special)
      if (special) return

      dec = max(0_default_int, min(decimals, PIC_FORMAT_MAX_DECIMALS))
      negative = is_negative(value)

      if (value == 0.0_dp) then
         ! Zero never carries a sign. Recognising a negative zero requires SIGN
         ! to distinguish the two signed zeros, which Fortran leaves processor
         ! dependent (F2018 16.9.165: the result is |A| if the processor cannot
         ! distinguish them), and Intel and AOCC do not distinguish them under
         ! their default fast floating point model. Emitting "-0.00" would
         ! therefore be compiler dependent, which is the one thing this module
         ! exists to avoid. A non-zero value that merely rounds to zero does
         ! keep its sign: SIGN is well defined for a non-zero argument.
         negative = .false.
         rounded = ""
         n_rounded = 0_default_int
         point_pos = 0_default_int
      else
         call expand_exact(abs(value), exact, n_exact, point_pos)
         n_keep = point_pos + dec
         call round_decimal(exact, n_exact, n_keep, rounded, n_rounded, bump)
         point_pos = point_pos + bump
      end if

      string = assemble_fixed(negative, rounded, n_rounded, point_pos, dec)

   end function to_string_fixed_dp