Integer to string, without padding. Digits are built by hand: an internal write costs
far more, and this is called for every token by the safety check.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | i |
the number |
pure function to_s(i) result(s) !! Integer to string, without padding. Digits are built by hand: an internal `write` costs !! far more, and this is called for every token by the safety check. integer, intent(in) :: i !! the number character(len=int_width(i)) :: s character(len=12) :: buf integer :: k, n n = i ! not abs(i), which overflows for -huge(i) - 1 k = len(buf) + 1 do k = k - 1 buf(k:k) = achar(iachar('0') + abs(mod(n, 10))) n = n/10 if (n == 0) exit end do if (i < 0) then k = k - 1 buf(k:k) = '-' end if s = buf(k:) end function to_s