anyinteger_to_64bit(3f) - [M_anything] convert integer any kind to integer(kind=int64) (LICENSE:PD)
Synopsis
Description
Options
Results
Example
Author
License
impure elemental function anyinteger_to_64bit(intin) result(value)
class(*),intent(in) :: intin integer(kind=int64) :: value
This function uses polymorphism to allow arguments of different INTEGER 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).
VALUEIN input argument of a procedure to convert to type INTEGER(KIND=int64). May be of KIND kind=int8, kind=int16, kind=int32, kind=int64.
The value of VALUIN converted to INTEGER(KIND=INT64).
Sample programResults
program demo_anyinteger_to_64bit 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 : anyinteger_to_64bit class(*),intent(in) :: invalue doubleprecision :: invalue_local doubleprecision :: squarei invalue_local=anyinteger_to_64bit(invalue) squarei=invalue_local*invalue_local end function squarei ! end program demo_anyinteger_to_64bit
16129.000000000000 127 \ 16129 1073676289.0000000 32767 \ 1073676289 4.6116860141324206E+018 2147483647 \ 4611686014132420609 8.5070591730234616E+037 9223372036854775807 \ 85070591730234615847396907784232501249 2.8948022309329049E+076 170141183460469231731687303715884105727 \ 28948022309329048855892746252171976962977213799489202546401021394546514198529
John S. Urban
Public Domain
anyinteger_to_64bit (3) | January 31, 2020 |