Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Alternatives to REAL

5 views
Skip to first unread message

James Van Buskirk

unread,
Dec 9, 2010, 1:23:09 AM12/9/10
to
As I said before, REAL is a very complex intrinsic if you count
specific names. Here is an example program:

C:\gfortran\clf\quadtest>type realtest3.f90
program realtest3
implicit none
intrinsic real
intrinsic realpart
intrinsic float
intrinsic sngl
intrinsic dfloat
intrinsic dreal
intrinsic dble
integer(1) v1
integer(2) v2
integer(4) v3
integer(8) v4
integer(16) v5
real(4) v6
real(8) v7
real(10) v8
real(16) v9
complex(4) v10
complex(8) v11
complex(10) v12
complex(16) v13

v1 = 1
v2 = 2
v3 = 3
v4 = 4
v5 = 5
v6 = 6
v7 = 7
v8 = 8
v9 = 9
v10 = (10,11)
v11 = (12,13)
v12 = (14,15)
v13 = (16,17)
! call irsub('real',real,v3)
! call crsub('realpart',realpart,v10)
! call irsub('float',float,v3)
! call drsub('sngl',sngl,v7)
! call zdsub('dreal',dreal,v11)
! call rdsub('dfloat',dfloat,v6)
! call rdsub('dble',dble,v6)
write(*,*) 'real stuff'
write(*,*) real(v1)
write(*,*) real(v2)
write(*,*) real(v3)
write(*,*) real(v4)
write(*,*) real(v5)
write(*,*) real(v6)
write(*,*) real(v7)
write(*,*) real(v8)
write(*,*) real(v9)
write(*,*) real(v10)
write(*,*) real(v11)
write(*,*) real(v12)
write(*,*) real(v13)
write(*,*) 'realpart stuff'
write(*,*) realpart(v10)
write(*,*) realpart(v11)
write(*,*) realpart(v12)
write(*,*) realpart(v13)
write(*,*) 'float stuff'
write(*,*) float(v1)
write(*,*) float(v2)
write(*,*) float(v3)
write(*,*) float(v4)
write(*,*) float(v5)
write(*,*) 'sngl stuff'
write(*,*) sngl(v6)
write(*,*) sngl(v7)
write(*,*) sngl(v8)
write(*,*) sngl(v9)
write(*,*) 'dreal stuff'
write(*,*) dreal(a=v11)
write(*,*) 'dfloat stuff'
write(*,*) dfloat(v1)
write(*,*) dfloat(v2)
write(*,*) dfloat(v3)
write(*,*) dfloat(v4)
write(*,*) dfloat(v5)
write(*,*) 'dble stuff'
write(*,*) dble(v1)
write(*,*) dble(v2)
write(*,*) dble(v3)
write(*,*) dble(v4)
write(*,*) dble(v5)
write(*,*) dble(v6)
write(*,*) dble(v7)
write(*,*) dble(v8)
write(*,*) dble(v9)
write(*,*) dble(v10)
write(*,*) dble(v11)
write(*,*) dble(v12)
write(*,*) dble(v13)
end program realtest3

subroutine irsub(label,fun,x)
implicit none
character(*) label
interface
function fun(x)
implicit none
integer, intent(in) :: x
real fun
end function fun
end interface
integer x

write(*,*) label//'(',x,') = ',fun(x)
end subroutine irsub

subroutine crsub(label,fun,x)
implicit none
character(*) label
interface
function fun(x)
implicit none
complex, intent(in) :: x
real fun
end function fun
end interface
complex x

write(*,*) label//'(',x,') = ',fun(x)
end subroutine crsub

subroutine drsub(label,fun,x)
implicit none
character(*) label
interface
function fun(x)
implicit none
double precision, intent(in) :: x
real fun
end function fun
end interface
double precision x

write(*,*) label//'(',x,') = ',fun(x)
end subroutine drsub

subroutine zdsub(label,fun,x)
implicit none
character(*) label
interface
function fun(x)
implicit none
complex(kind(1.0d0)), intent(in) :: x
double precision fun
end function fun
end interface
complex(kind(1.0d0)) x

write(*,*) label//'(',x,') = ',fun(x)
end subroutine zdsub

subroutine rdsub(label,fun,x)
implicit none
character(*) label
interface
function fun(x)
implicit none
real, intent(in) :: x
double precision fun
end function fun
end interface
real x

write(*,*) label//'(',x,') = ',fun(x)
end subroutine rdsub

C:\gfortran\clf\quadtest>gfortran realtest3.f90 -orealtest3

C:\gfortran\clf\quadtest>realtest3
real stuff
1.0000000
2.0000000
3.0000000
4.0000000
5.0000000
6.0000000
7.0000000
8.0000000
9.0000000
10.000000
12.000000000000000
14.000000000000000000
16.000000000000000000000000000000000
realpart stuff
10.000000
12.000000000000000
14.000000000000000000
16.000000000000000000000000000000000
float stuff
1.0000000
2.0000000
3.0000000
4.0000000
5.0000000
sngl stuff
6.0000000
7.0000000
8.0000000
9.0000000
dreal stuff
12.000000000000000
dfloat stuff
1.0000000000000000
2.0000000000000000
3.0000000000000000
4.0000000000000000
5.0000000000000000
dble stuff
1.0000000000000000
2.0000000000000000
3.0000000000000000
4.0000000000000000
5.0000000000000000
6.0000000000000000
7.0000000000000000
8.0000000000000000
9.0000000000000000
10.000000000000000
12.000000000000000
14.000000000000000
16.000000000000000

As I mentioned before, REAL itself should have a specific name that
I can't detect in gfortran. But also REALPART isn't well-documented.
This name is only generic in gfortran and its argument is called 'A',
not 'Z'. Like IMAGPART, it only accepts COMPLEX arguments, of any
KIND. Maybe it would be good to make the argument for REALPART Z
instead of A for consistency with IMAGPART and the documentation.
Also it might make sense to add a non-bulleted specific name for
REALPART to be consistent with IMAGPART, or to delete the specific
name for IMAGPART.

Moving on to FLOAT, we see that gfortran considers it to be generic,
accepting any KIND of INTEGER argument, which the documentation
doesn't point out and this usage is an extension to the standard.
Also it doesn't point out that its specific name is bulleted, both by
the standard and the compiler.

SNGL is also considered by the compiler to be generic, unlike what
its documentation and the standard say. Also the specific name
takes a REAL(8) argument, not INTEGER(8) and is bulleted both by
the standard and the compiler.

DREAL is documented by the standard as a generic function would be,
but it seems to make more sense to me to place it as a specific
name under the REAL intrinsic. gfortran seems to treat it as a
bulleted specific name taking a COMPLEX(8) argument called 'A', not
'Z' as the documentation says.

DFLOAT, like FLOAT, is generic, taking any KIND of INTEGER argument.
Again, neither the standard nor the gfortran documentation would
tell you this. Its phantom bulleted specific name seems to take a
REAL(4) argument, not an INTEGER(4) argument, a circumstance which,
even though only detectable in error messages, still seems strange
and contrary to gfortran documentation.

DBLE is consistent with gfortran documentation and the standard.
The only thing I would mention is that it seems to have a
phantom bulleted specific name, accepting a REAL(4) argument.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


steve

unread,
Dec 9, 2010, 10:49:44 AM12/9/10
to
On Dec 8, 10:23 pm, "James Van Buskirk" <not_va...@comcast.net> wrote:
> As I said before, REAL is a very complex intrinsic if you count
> specific names.

When checking the conformance of gfortran to a
specific standard, it is prudent to actually restrict
gfortran to that standard via the -std= option.
Your program does not come close to compiling
with -std=f95.

As far as issues with the documentation goes, you've
hit upon an area where contributions from new
contributors would be gladly accepted. Documentation
is way down the list of priorities for items that need
to be fixed.

--
steve

0 new messages