single precision or double precision? 
Author Message
 single precision or double precision?

I am teaching our graduate scientific computing class and its associated lab
class (on NeXT machines).  To understand the effects of round-off errors I
teach the students how to write their programs using the generic function
names so that it is easy to convert the programs between single and double
precision.

I have written a little subroutine which can be put at the beginning of
their programs to determine the precision.  It returns this in a variable
which can be tested for the precision.  (This is useful when using Linpack
because the subroutine names are different in different precisions.)  It
also returns the machine epsilon for this precision (it returns it in a
single precision argument since I have to choose one or the other).
(I realize that the students can set an integer variable by hand to show the
precision.  However, when switching between precisions it is easy to forget
to change this variable and so it seems worthwhile to have this checked by
the computer.)

Below is how I am presently checking the precision.  Notice that I change
precision by using, or commenting out, the "implicit double precision"
statement.  It can also be done by declaring all arguments and changing
between "real" and "double precision" using emacs or another editor.

From my reading of the ANSI standard I think the code below should work
(because double precision MUST use more bits than single precision).
Of course, I am not sure that this always works in REAL computers.  I would
appreciate any comments.  It probably is worth posting to the net as opposed
to e-mail.

      program main
c      implicit double precision (a-h,o-z)
      double precision testdp
      real epsssp
      test13 = 1.e0/3.e0
      testdp = test13
      call spordp(testdp,ispodp,epsssp)
      ...
      subroutine spordp(testdp,
     $ ispodp,epsssp)
      double precision testdp,f1d3dp
      real epsssp,f1d3sp
      f1d3dp = 1.e0/3.e0
      f1d3sp = 1.d0/3.d0
      if ( testdp .eq. f1d3dp ) then
        ispodp = 2
        ... (calculate machine epsilon)
      else if ( testdp .eq. dble(f1d3sp) ) then
        ispodp = 1
        ... (calculate machine epsilon)
      else
        ... (ERROR)
      end if
      ...

Thanks,
Ed Overman



Thu, 27 Mar 1997 09:14:23 GMT  
 single precision or double precision?

Quote:

> I am teaching our graduate scientific computing class and its associated lab
> class (on NeXT machines).  To understand the effects of round-off errors I
> teach the students how to write their programs using the generic function
> names so that it is easy to convert the programs between single and double
> precision.

We also teach scientific computing and have a lab of NeXtstations w/fortran.
I (personal opinion) think it is best to not even mention the non-generic names
for functions, except in some historical discussion about the evolution of Fortran.
I always use generic names and consider the type-specific names obsolete.

Quote:
> I have written a little subroutine which can be put at the beginning of
> their programs to determine the precision.  It returns this in a variable

Knowing about precision is a good idea. So good, in fact, that there are
built-in intrinsic functions in Fortran which return this information. There
is no need to write your own routine.  If your compiler isn't up to the
standard, you should get a better one. Given that NeXT does not supply a
Fortran compiler, you have to go third party.  I can highly recommend the
compiler for NeXT from NAG. We use it in our labs and I also do all my software
development with it. It seems to be standard conforming and it gives good
compile-time error messages.

Cheers,
Bill Long
Department of Physics
University of Wisconsin-Madison



Fri, 28 Mar 1997 11:58:12 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Convert single precision to double precision

2. double precision vs. single precision

3. Double precision runs fast tan single precision in MS Fortran

4. HP Fortran question: precision of double-precision?

5. Single and double precision versions of IMSL routines give different

6. Single and double precision versions of IMSL routines give different results

7. Single / Double Precision Issue

8. single/double precision

9. Single to double precision

10. double precision skiped to single ?

11. Mixing double and single precision

12. Single/Double Precision

 

 
Powered by phpBB® Forum Software