On 1998-06-26 at 9:05 h, Dr W.W. Schulz has written::
> PS: the code below lets you check the various kinds of integers and
> floating points implemented on your machine. It is also F compatible.
Perhaps F compatible -- but still faulty :-)
> program kinds
..
> ! Find Precisions.
> dp = 1
> i = 0
> do
> f1 = selected_real_kind( p = dp )
> f2 = selected_real_kind( p = dp +1 )
..
> if( f1/=f2 ) then
> i = i +1
> fp(i)%p = dp
> fp(i)%k = f1
> end if
> dp = dp +1
> end do
>
> ! Find Ranges:
> er = 1
> i = 0
> do
> f1 = selected_real_kind( r = er )
> f2 = selected_real_kind( r = er +1 )
.. ! as above, mutatis mutandis
> er = er +1
> end do
The problem with this code is that it independently collects ranges and
precisions. It tacitly assumes that there are as many different ranges
as there are precisions, and that they are ordered correspondingly:
> do i=1,count( fp%p>0 )
> write(unit=*,fmt="(I5,I12,I10)") fp(i)%k, fp(i)%p, fp(i)%r
> end do
When an implementation features two kinds with different precisions
but equal ranges, the program will give erroneous results:
> Kind Precision Range
> 4 6 37
> 8 15 307
> 16 31 0
Similar errors will occur for two different ranges but equal precision.
Rather, for every precision found, the corresponding ranges must be
sought; however, you have to exclude the cases when you have asked for a
greater range but not for the full precision that comes with the kind
thus found. (Or vice versa.) For details, see below.
On the same implementation, as above, the corrected program finds:
> Kind Precision Range
> 4 6 37
> 8 15 307
> 16 31 307
Best wishes,
Otto Stolz
------- Corrected program -------
module kind_type
implicit none
type, public :: fp_kind
integer :: p, r, k
end type fp_kind
type, public :: int_kind
integer :: r, k
end type int_kind
end module kind_type
program kinds
! Displays all floating point and integer kinds implemented
! on a machine together with range and precision.
use kind_type
implicit none
type(int_kind), dimension(20) :: ik
type(fp_kind), dimension(20) :: fp
integer :: dp, er, i, k, f1, f2
fp = fp_kind(0,0,0)
ik = int_kind(0,0)
! Floating Points implemented
! Find Precisions.
dp = 1
i = 0
do
f1 = selected_real_kind( p = dp )
f2 = selected_real_kind( p = dp +1 )
if (f1<1) then ! Precision >=dp is not implemented
exit
else if(f1/=f2) then
! Find Ranges for given precision:
er = 1
do
f1 = selected_real_kind( p = dp, r = er )
f2 = selected_real_kind( p = dp, r = er+1)
if (f1<1) then ! Range >=er is not implemented
exit
else if (f1/=f2) then
! Í
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|