Re: whole number constants



<dancerchris@xxxxxxxxxxxxx> wrote:

I like label 50 as well but then what about cancellation, for example:

real(dp), parameter :: pi = 3.1415926535_dp
real(dp), parameter :: two = 2.0_dp

real(dp) :: x,y

! this looks good/ledgable but.....

x = 2*pi
y = x/2

! does the following result...

if (y == pi) then

I understand they may never be equal but then I am trying to establish
a truly constant value to two so they are equal not just to the "dp"
accuracy.

I think you are confusing yourself by inventing concepts that don't
exist. There is no such thing as a distinction between a "truly
constant" value and any other constant. A constant is a constant.

And no double precision constant is ever accurate to more than the
double precision accuracy. It almost sounds like you are looking for
infinite precision. There ain't no such animal; fiddling with the syntax
won't change that.

As you note, equality tests for floating point values are inherently
problematic. But this has *ZERO* to do with how you wrote the constant
pi. I repeat the *ZERO*. If you are thinking that there is even a hint
of a relationship, then you are confusing yourself with something, and
I'm not even quite sure what.

As a bit of an aside, this is not at all an example of cancellation
anyway. Multiplying and dividing by 2 is a particularly bad example if
that's what you are trying to get at. Multiplication and division by 2
will be exact on most machines. (IBM mainframes provide one of the few
counterexamples).

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.