stdlib_str2num Module

The stdlib_str2num module provides procedures and interfaces for conversion of characters to numerical types. Currently supported: integer and real. (Specification)

This code was modified from https://github.com/jalvesz/Fortran-String-to-Num by Alves Jose And was possible thanks to all the discussions in this thread https://fortran-lang.discourse.group/t/faster-string-to-double/

Known precisions limits of current proposal : Conversion to double precision is exact up to epsilon(0.0_dp) example:

input : 123456.78901234567890123456789012345678901234567890+2

formatted read : 12345678.90123457

to_num : 12345678.90123457

difference abs : 0.1862645149230957E-08

difference rel : 0.1508742584455759E-13%

Conversion to quadruple precision can deviate at about 200*epsilon(0.0_qp) example:

input : 0.140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125E-443

formatted read : 0.140129846432481707092372958328991608E-443

to_num : 0.140129846432481707092372958328996233E-443

difference abs : 0.4625E-475

difference rel : 0.3300E-029%



Interfaces

public interface to_num

Conversion of strings to numbers (Specification)

  • private elemental function to_int8(s, mold) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: s

    input string

    integer(kind=int8), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    Return Value integer(kind=int8)

    Output integer(int8) value

  • private elemental function to_int16(s, mold) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: s

    input string

    integer(kind=int16), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    Return Value integer(kind=int16)

    Output integer(int16) value

  • private elemental function to_int32(s, mold) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: s

    input string

    integer(kind=int32), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    Return Value integer(kind=int32)

    Output integer(int32) value

  • private elemental function to_int64(s, mold) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: s

    input string

    integer(kind=int64), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    Return Value integer(kind=int64)

    Output integer(int64) value

  • private elemental function to_sp(s, mold) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: s

    input string

    real(kind=sp), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    Return Value real(kind=sp)

    Output real(sp) value

  • private elemental function to_dp(s, mold) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: s

    input string

    real(kind=dp), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    Return Value real(kind=dp)

    Output real(dp) value

public interface to_num_from_stream

Conversion of a stream of values in a string to numbers (Specification)

  • private function to_int8_from_stream(s, mold, stat) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=:), pointer :: s

    input string

    integer(kind=int8), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    integer(kind=int8), intent(inout), optional :: stat

    Return Value integer(kind=int8)

    Output integer(int8) value

  • private function to_int16_from_stream(s, mold, stat) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=:), pointer :: s

    input string

    integer(kind=int16), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    integer(kind=int8), intent(inout), optional :: stat

    Return Value integer(kind=int16)

    Output integer(int16) value

  • private function to_int32_from_stream(s, mold, stat) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=:), pointer :: s

    input string

    integer(kind=int32), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    integer(kind=int8), intent(inout), optional :: stat

    Return Value integer(kind=int32)

    Output integer(int32) value

  • private function to_int64_from_stream(s, mold, stat) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=:), pointer :: s

    input string

    integer(kind=int64), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    integer(kind=int8), intent(inout), optional :: stat

    Return Value integer(kind=int64)

    Output integer(int64) value

  • private function to_sp_from_stream(s, mold, stat) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=:), pointer :: s

    input string

    real(kind=sp), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    integer(kind=int8), intent(inout), optional :: stat

    Return Value real(kind=sp)

    Output real(sp) value

  • private function to_dp_from_stream(s, mold, stat) result(v)

    Arguments

    Type IntentOptional Attributes Name
    character(len=:), pointer :: s

    input string

    real(kind=dp), intent(in) :: mold

    dummy argument to disambiguate at compile time the generic interface

    integer(kind=int8), intent(inout), optional :: stat

    Return Value real(kind=dp)

    Output real(dp) value