dble(3f) - [M_overload::TYPE] allow dble(3f), real(3f), int(3f) to take character arguments (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
dble(3f), real(3f), and int(3f) extension:
pure elemental doubleprecision function dble(value) pure elemental real function real(value) pure elemental int function int(value)
All the intrinsics dble(3f), real(3f), and int(3f) to take a character string as an argument, assuming it represents a numeric value; or a logical value or expression.
o [char46]true. is 0 o [char46]false. is 1
value string or logical expression or value to convert to a numeric value If an error occurs zero is returned.
A numeric value
Sample usage:
program demo_dbleResults:use, intrinsic :: iso_fortran_env, only : & & integer_kinds, int8, int16, int32, int64 use, intrinsic :: iso_fortran_env, only : & & real32, real64, real128
use M_overload, only : int, real, dble use M_overload, only : merge implicit none character(len=*), parameter :: gen=(*("[",g0,"]":,",")) ! basics ! note returns int64 write(*,gen) int(1234)*2 write(*,gen) real(1234.56789)*2 write(*,gen) dble(1234.5678901234567)*2 ! tests if(int(1234) .eq. 1234 ) & & write(*,*)int("STRING") works if(abs(real(1234.56789) - 1234.56789) .lt. 2*epsilon(0.0)) & & write(*,*)real("STRING") works if(abs(dble(1234.5678901234567) - 1234.5678901234567d0) .lt. & & epsilon(0.0d0)) & & write(*,*)dble("STRING") works ! logical arguments work as well ! so let us settle this once and for all write(*,*).true. is,int(.true.) write(*,*).false. is,int(.false.) write(*,*)LOGICAL ARRAY , dble([.false., .true., .false., .true.]) write(*,*) merge(int works for .FALSE.,int fails for .FALSE., & & int(.FALSE.).ne.0) write(*,*) merge(int works for .TRUE.,int fails for .TRUE., & & int(.TRUE.).eq.0) ! and also note the argument can be metamorphic ! call a function with a metamorphic argument so values can be ! any values that represent a numeric value ... write(*,*)METAMORPHIC , promote(1,1.0,1.0d0) write(*,*)METAMORPHIC , promote(3,(2.0,0.0),.true.) write(*,*)METAMORPHIC , promote(3,3,3) write(*,*)METAMORPHIC , promote(.true.,.false.,.true.) write(*,*)METAMORPHIC , promote((3.0,4.0),0.0,0)
contains function promote(value1,value2,value3) class(*),intent(in) :: value1 class(*),intent(in) :: value2 class(*),intent(in) :: value3 doubleprecision,allocatable :: promote promote=sum([dble(value1),dble(value2),dble(value3)]) end function promote
end program demo_dble
> [2468] > [2469.13574] > [2469.1357802469133] > int("STRING") works > real("STRING") works > dble("STRING") works > .true. is 0 > .false. is 1 > LOGICAL ARRAY 1.0000 0.0000 1.0000 0.0000 > int works for .FALSE. > int works for .TRUE. > METAMORPHIC 3.0000000000000000 > METAMORPHIC 3.0000000000000000 > METAMORPHIC 9.0000000000000000 > METAMORPHIC 1.0000000000000000 > METAMORPHIC 0.0000000000000000
John S. Urban
Public Domain
Nemo Release 3.1 | dble (3) | February 23, 2025 |