C Library Functions  - anyscalar_to_double (3)

NAME

anyscalar_to_double(3f) - [M_anything] convert integer or real parameter of any kind to doubleprecision (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Results
Examples
Author
License

SYNOPSIS

pure elemental function anyscalar_to_double(valuein) result(d_out)

    class(*),intent(in)  :: valuein
    doubleprecision      :: d_out

DESCRIPTION

This function uses polymorphism to allow input arguments of different types. It is used to create other procedures that can take many scalar arguments as input options.

OPTIONS

VALUEIN
  input argument of a procedure to convert to type DOUBLEPRECISION. May be of KIND kind=int8, kind=int16, kind=int32, kind=int64, kind=real32, kind=real64, or kind=real128

RESULTS

D_OUT The value of VALUIN converted to doubleprecision (assuming it is actually in the range of type DOUBLEPRECISION).

EXAMPLES

Sample program

    program demo_anyscalar_to_double
    use, intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
    use, intrinsic :: iso_fortran_env, only : real32, real64, real128
    implicit none
       ! call same function with many scalar input types
       write(*,*)sqrtany(2_int8)
       write(*,*)sqrtany(2_int16)
       write(*,*)sqrtany(2_int32)
       write(*,*)sqrtany(2_int64)
       write(*,*)sqrtany(2.0_real32)
       write(*,*)sqrtany(2.0_real64)
       write(*,*)sqrtany(2.0_real128)
    contains

function sqrtany(invalue) result (value) use M_anything, only : anyscalar_to_double class(*),intent(in) :: invalue doubleprecision :: value value=sqrt(anyscalar_to_double(invalue)) end function sqrtany

end program demo_anyscalar_to_double

Results:

    >    1.4142135623730951
    >    1.4142135623730951
    >    1.4142135623730951
    >    1.4142135623730951
    >    1.4142135623730951
    >    1.4142135623730951
    >    1.4142135623730951

AUTHOR

John S. Urban

LICENSE

    MIT


Nemo Release 3.1 anyscalar_to_double (3) February 23, 2025
Generated by manServer 1.08 from 851237d2-13b3-4943-b72b-095d25f522d6 using man macros.