Re: Rounding off double precision



Gerry Ford wrote:
"Dave Seaman" <dseaman@xxxxxxxxxxxx> wrote in message news:fstcm0$4eh$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mon, 31 Mar 2008 22:04:56 -0700, Gerry Ford wrote:



"Dave Seaman" <dseaman@xxxxxxxxxxxx> wrote in message
news:fssah4$iv8$2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mon, 31 Mar 2008 19:43:46 -0700 (PDT), Bamm wrote:
A parameter is not a literal constant and vice-versa.
what's the difference? I thought parameter was fortran's way of
declaring a constant.
A parameter is a symbolic constant, not a literal constant.
I think illustrative source snippets go a long way:
INTEGER, PARAMETER :: dp = kind(1d0)
is probably the parameter I get the most mileage from.
And in your example, "dp" is a symbolic constant and "1d0" is a literal
constant.
I didn't know that.

INTEGER, PARAMETER :: qp = kind(???)

Is there an analogous literal here? It sounds like I'm trying to buy pot.:-)

It depends on what you want to do. If the processor doesn't
support quad precision, there is no statement that will work. ;)

But, if you need quad and want the program to fail at compile
time if quad isn't available, then something like
integer, parameter :: qp = kind (precision(1.0D0) + 5)
real (qp) :: xxx
will give you a higher precision on machines that support more than
single and double.

If you want to be able to use quad if it is there, and use double
otherwise, something like

integer, parameter :: qp_help = kind (precision(1.0D0) + 5)
integer, parameter :: qp = max(dp, qp_help)

will work on any processor that uses increasing kind values for
increasing precisions. James van Buskirk (I think) has a much better
way that works in the general case; but it's too complicated
for me to remember :( .

*** Hendrickson
.