C Library Functions  - anyscalar_to_int64 (3)

NAME

anyscalar_to_int64(3f) - [M_anything] convert intrinsic scalar types to integer(kind=int64) (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Results
Example
Author
License

SYNOPSIS

impure elemental function anyscalar_to_int64(valin) result(value)

    class(*),intent(in) :: valin
    integer(kind=int64) :: value

DESCRIPTION

This function uses polymorphism to allow arguments of different types as input. It is typically used to create other procedures that can take many scalar arguments as input options, equivalent to passing the parameter VALUE as int(VALUE,0_int64) for integer; nint(VALUE,0_int64) for real values, returning 0_int64 for .true. and 1_int64 for logical, and the same as int(VALUE,0_int64) for character variables if the character variables represent an integer value.

OPTIONS

VALUEIN
  input argument of a procedure to convert to type INTEGER(KIND=int64).

RESULTS

The value of VALUIN converted to INTEGER(KIND=INT64).

EXAMPLE

Sample program

    program demo_anyscalar_to_int64
    use, intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
    implicit none
       ! call same function with many scalar input types
       write(*,*)squarei(huge(0_int8)),huge(0_int8) , &
       & ’16129’
       write(*,*)squarei(huge(0_int16)),huge(0_int16) , &
       & ’1073676289’
       write(*,*)squarei(huge(0_int32)),huge(0_int32) , &
       & ’4611686014132420609’
       write(*,*)squarei(huge(0_int64)),huge(0_int64) , &
       & ’85070591730234615847396907784232501249’
    contains
    !
    function squarei(invalue)
    use M_anything, only : anyscalar_to_int64
    class(*),intent(in)  :: invalue
    doubleprecision      :: invalue_local
    doubleprecision      :: squarei
       invalue_local=anyscalar_to_int64(invalue)
       squarei=invalue_local*invalue_local
    end function squarei
    !
    end program demo_anyscalar_to_int64

Results

   16129.000000000000       127 \
   16129
   1073676289.0000000       32767 \
   1073676289
   4.6116860141324206E+018  2147483647 \
   4611686014132420609
   8.5070591730234616E+037  9223372036854775807 \
   85070591730234615847396907784232501249
   2.8948022309329049E+076 170141183460469231731687303715884105727 \
   28948022309329048855892746252171976962977213799489202546401021394546514198529

AUTHOR

John S. Urban

LICENSE

    MIT


Nemo Release 3.1 anyscalar_to_int64 (3) July 22, 2023
Generated by manServer 1.08 from d514f60b-f992-4828-94c6-bc407af4ddb5 using man macros.