Re: Newbie question about double precision
From: Richard Edgar (rge21_at_astro.su.se)
Date: 12/04/03
- Next message: David Frank: "Re: Converting Fortran module<->C++ structure"
- Previous message: Michael Metcalf: "Re: Newbie question about double precision"
- In reply to: Michael Metcalf: "Re: Newbie question about double precision"
- Next in thread: John Harper: "Re: Newbie question about double precision"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 04 Dec 2003 17:56:27 +0100
Michael Metcalf wrote:
> "Richard Edgar" <rge21@astro.su.se> wrote in message
> news:bqnj3v$dpc$1@news.su.se...
>
>>One related nasty is the following:
>>
>>REAL (KIND=QP):: third = 1_QP/3_QP
>>
>>isn't what you think it is, either. This sets the variable 'third' to be
>>equal to zero (probably.....). The reason? In Fortran, KINDs are
>>specified using integers, and so there is a good chance (although not a
>>certainty) that QP can also represent a valid _integer_ KIND. So the
>>compiler does 1/3 (integer divide), gets the answer zero, and then
>>stores this in the quad precision variable 'third'
>
> I'm not clear why you think this is any different to writing, for default
> real third, = 1/3 rather than = 1./3., also an error that is easy to make.
Because, when I've gone to the trouble of typing those extra '_QP's, I'd
like them to have an effect (I do appreciate that I was _unlucky_ that
QP was also a valid INTEGER type)! When this one first bit me, I was
very fortunate that the zeros thereby produced meant that the subroutine
in question immediately started producing garbage. Otherwise, the bug
could have stayed for a very long time (indeed, I might not even be
aware of it now).
Or put another way, I'd added the '_QP' tags _because_ I was aware of
the 1/3 vs 1./3. problem, and I expected them to protect me from it.
>>Whether your original problem is an error in the standard is very much a
>>matter of opinion. It would be nice if variables didn't have to be
>>tagged, but they do.
>
> It's not an error in the standard as it would otherwise have to be a
> special-case exception to the general rules governing expressions and
> assignments. It was realised at the time that there might be a backwards
> incompatibility with the way some F77 compilers had dealt with it in DATA
> statements, and that was duly noted in the new standard and the books
> describing it.
Mea culpa - 'Error' was too strong a word. This was what I was alluding
to when I mentioned 'special cases' and the like. I should have been
clearer. I believe that it would be _possible_ to specify a language
such that the required types could be deduced, but the established rules
of Fortran do not allow it.
Richard
- Next message: David Frank: "Re: Converting Fortran module<->C++ structure"
- Previous message: Michael Metcalf: "Re: Newbie question about double precision"
- In reply to: Michael Metcalf: "Re: Newbie question about double precision"
- Next in thread: John Harper: "Re: Newbie question about double precision"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|