Jan van Oosterwijk <[log in to unmask]> wrote 2000-09-21
10:00:
>
> James,
>
> At 11:33 20-09-2000 -0600, James Giles <[log in to unmask]>
wrote:
> >W. J. Metzger <[log in to unmask]> wrote:
> >...
> >>How about sumx = sum( real( x, kind(0d0) ) )
> >
> >Or (possibly better):
> >
> > sumx = sum( real(x, kind(sumx) ) )
> >
> >This way you can change to double, quad, or whatever by
> >simply redeclaring SUMX. No need to rewrite code fragments.
>
> This is all very interesting, but does it help you much?
> X is single precision, and converting it to double, does not add a bit to
this
> precision, or ??
>
> Example:
>
> ! [JvO] 2000-09-21 xx.f90
> real :: x = 123.4567
> double precision :: y
>
> y = dble(x)
> print *, x, y
> end
>
> D:\FORTRAN\TEST>xx ! From Salford FTN95:
> 123.457 123.456703186
>
> D:\FORTRAN\TEST>xx ! From Absoft F90
> 123.457 123.456703186035
>
>
> >J. Giles
> >
There are cases when converting to double add bits to the result:
program test
real :: sumsp
double precision :: sumdp
real :: x(3) = (/123.5, 1e-12, -123.5 /)
sumsp = sum( x )
if( sumsp > 0.0 ) then
print *, 'sumsp > 0.0'
else
print *, 'sumsp <= 0.0'
endif
sumdp = sum( real( x, kind(0d0) ) )
if( sumdp > 0.0 ) then
print *, 'sumdp > 0.0'
else
print *, 'sumdp <= 0.0'
endif
end program
DVF6.1a _without_ optimization on Win NT gives :
sumsp <= 0.0
sumdp > 0.0
Compiling with optimization change the behavior of this example,
sumsp becomes > 0.0. But I guess one can find/write programs
where the difference remains.
Greetings,
Kurt
--------------------------------
Kurt Kaellblad, Ph.D. <[log in to unmask]>
Building Science, Lund Institute of Technology
Lund University, Sweden
>
>
> --
>
> Meilleures Salutations,
> Kindest Regards,
> /---
> Jan van Oosterwijk
> Computing Centre
> Delft University of Technology
> Postbus 354
> 2600 AJ Delft
> Netherlands / Pays-Bas
> mailto:[log in to unmask]
> Phone: +31 15 278 50 17
> Fax: +31 15 278 37 87
>
>
>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|