NAG Routines in Different Precisions
Written by David Sayers, NAG Principal Technical Consultant
precision it computes in determined by the precision of the arguments? So, for
example, your program might contain:
returned to r. If x were double or quadruple precision then the corresponding
double or quadruple computations would be performed.
I can imagine a number of scenarios where this facility
might be useful, but I invite your comments on how common these might be:
Single precision might be useful as once again single precision calculation becomes faster than double precision. So the user might want to trade accuracy for speed.
- Secondly, single precision used to be the natural interface to many graphics packages. I am not sure whether this is still the case. Would it be useful to have the capability for this reason?
- Double precision, the precision now offered, is generally ‘about right’ for most computations, but sometimes extra precision is needed for the trickiest calculation. Under these circumstances quadruple precision might be necessary. How common is this requirement amongst our users?
- If a computation is made with two different precisions and the resulting answers are broadly similar then a certain level of confidence might be gained from these computations. If on the other hand the results are very different this may indicate that the original problem was ill-conditioned. The ability to do this test easily might be something our
users want. Do you think this is so?
From the developers point of view modern Fortran makes it
easy to provide these facilities:
Module Procedure dks_1, dks_2,
End Interface dks
Real (Kind=1) :: x
Print *, 'single precision'
End Subroutine dks_1
Real (Kind=2) :: x
Print *, 'double precision'
End Subroutine dks_2
Real (Kind=3) :: x
Print *, 'quadruple precision'
End Subroutine dks_3
End Module dks1
Real (Kind=1) :: x1
Real (Kind=2) :: x2
Real (Kind=3) :: x3
End Program main
others might use a ‘Byte convention’ i.e. the kind number matches the number of
bytes of storage. Thus some compilers use ‘Real
(Kind=4)’ to denote single precision and ‘Real
(Kind = 8)’ to denote double precision.