anyinteger_to_128bit(3f) - [M_anything] convert integer of any kind to integer(kind=128)
Synopsis
Description
Options
Results
Example
pure elemental function anyinteger_to_128bit(intin) result(ii38)
integer(kind=int128) function anyinteger_to_128bit(value) class(*),intent(in) :: intin integer(kind=int8|int16|int32|int64|int128) :: value
This function uses polymorphism to allow arguments of different types generically. It is used to create other procedures that can take many scalar arguments as input options, equivalent to passing the parameter VALUE as int(VALUE,0_int128).
VALUEIN input argument of a procedure to convert to type INTEGER(KIND=128). May be of KIND kind=int8, kind=int16, kind=int32, kind=int64, kind=int128.
The value of VALUIN converted to INTEGER(KIND=INT128).
Sample programResults
program demo_anyinteger_to_128bit use M_anything, only : int128 use 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 write(*,*)squarei(huge(0_int128)),huge(0_int128) , & & 28948022309329048855892746252171976962977213799489202546401021394546514198529 contains ! function squarei(invalue) use M_anything, only : anyinteger_to_128bit, int128 class(*),intent(in) :: invalue doubleprecision :: invalue_local doubleprecision :: squarei invalue_local=anyinteger_to_128bit(invalue) squarei=invalue_local*invalue_local end function squarei ! end program demo_anyinteger_to_128bit
16129.000000000000 127 \ 16129 1073676289.0000000 32767 \ 1073676289 4.6116860141324206E+018 2147483647 \ 4611686014132420609 8.5070591730234616E+037 9223372036854775807 \ 85070591730234615847396907784232501249 2.8948022309329049E+076 170141183460469231731687303715884105727 \ 28948022309329048855892746252171976962977213799489202546401021394546514198529
anyinteger_to_128bit (3) | March 28, 2019 |