From: robin on
"Luka Djigas" <ldigas@___gmail___.com> wrote in message news:9n9jp5pge81lpmv4qfk810rugdbqupvike(a)4ax.com...
| On Thu, 11 Mar 2010 14:32:57 -0800, nospam(a)see.signature (Richard Maine) wrote:
|
| >
| >Anyway, spilt milk aside, the thing to understand is that dp above is
| >just an integer parameter. Odds are that it is 8, though that will vary.
| >In any case, it is a named parameter for some integer value. That is
| >*ALL* it is. The fact that its value was computed using
| >selected_real_kind does *NOT* restrict it to being used as a real kind
| >parameter. That's the most obviously useful way to use it, but you can
| >use it anywhere else that you could use an integer parameter with the
| >value 8 (or whatever).
| >
|
| I find this part terribly confusing. Not your answer per se, but the part about reals and integers.
| If a parameter is declared as real, shouldn't it be considered as such even with the
| dot missing ?

The parameter is REAL, because it is declared REAL.
You have "declared" the constant to be an INTEGER.
The fact that you have "declared" the constant to be INTEGER
doesn't make it REAL.
The fact that you have assigned an INTEGER constant to a REAL variable
doesn't make the constant REAL. It is still an INTEGER.


From: robin on
"glen herrmannsfeldt" <gah(a)ugcs.caltech.edu> wrote in message news:hncbb7$ddb$1(a)naig.caltech.edu...
| Luka Djigas <ldigas@___gmail___.com> wrote:
| > On Thu, 11 Mar 2010 14:32:57 -0800, nospam(a)see.signature (Richard Maine) wrote:
|
| > I find this part terribly confusing. Not your answer per se,
| > but the part about reals and integers.
|
| > If a parameter is declared as real, shouldn't it be considered
| > as such even with the dot missing ?
|
| Yes, a PARAMETER declared REAL has type REAL, even with the dot missing.
| The usual rules for expressions evaluation still apply, though,
| in determining the value.
|
| REAL A
| A=5/2
|
| gives A the REAL value 2.0, after converting the INTEGER 2
| to REAL.

An unfortunate choice of values! The constant "2" in the
expression "5/2" is NOT real. It is an integer.
It's the INTEGER-VALUED expression "5/2" that yields 2 exactly,
and it is that which is converted fo REAL for assignment to "A".


From: robin on
"e p chandler" <epc8(a)juno.com> wrote in message news:hncc0c$bgj$1(a)news.eternal-september.org...
|
| "Luka Djigas" <ldigas@___gmail___.com> wrote in message
| news:9n9jp5pge81lpmv4qfk810rugdbqupvike(a)4ax.com...
| >
| > I find this part terribly confusing. Not your answer per se, but the part
| > about reals and integers.
| > If a parameter is declared as real, shouldn't it be considered as such
| > even with the
| > dot missing ?
|
| But that does not make sense, though I too was confused by the
|
| d=1_dp / 2_dp
|
| I have learned that the types of operands on the right are not promoted to
| (or related to) the type of the variable on the left. Instead, 1/2 is
| truncated to 0 and assigned to d.
|
| Suppose for the sake of argument that we want this type of error to be
| detected. dp is of type integer. Any other integer that evaluates to a valid
| kind for an integer could be mis-used in the same way without producing an
| error.
| Yet "dp" is not bound in any way to type "real". There is no type in Fortran
| such as "kind_specifier_of_real". Perhaps there should be, but now it's
| probably too late as that would break existing code unless some *new*
| inquiry functions were added to the language that returned enumerators of
| the proper "type". (Sorry about that!)

There's no need whatsoever for anything like that.

All that is required is for vendors to use different kind numbers
for EVERY kind type.

This is perfectly permissible, since the kind numbers are entirely arbitrary.

Thus, the problem could be solved virtually immediately.


From: e p chandler on

"robin" <robin_v(a)bigpond.com> wrote in message
news:WMqmn.12597$pv.5700(a)news-server.bigpond.net.au...
> "e p chandler" <epc8(a)juno.com> wrote in message
> news:hncc0c$bgj$1(a)news.eternal-september.org...
> |
> | "Luka Djigas" <ldigas@___gmail___.com> wrote in message
> | news:9n9jp5pge81lpmv4qfk810rugdbqupvike(a)4ax.com...
> | >
> | > I find this part terribly confusing. Not your answer per se, but the
> part
> | > about reals and integers.
> | > If a parameter is declared as real, shouldn't it be considered as such
> | > even with the
> | > dot missing ?
> |
> | But that does not make sense, though I too was confused by the
> |
> | d=1_dp / 2_dp
> |
> | I have learned that the types of operands on the right are not promoted
> to
> | (or related to) the type of the variable on the left. Instead, 1/2 is
> | truncated to 0 and assigned to d.
> |
> | Suppose for the sake of argument that we want this type of error to be
> | detected. dp is of type integer. Any other integer that evaluates to a
> valid
> | kind for an integer could be mis-used in the same way without producing
> an
> | error.
> | Yet "dp" is not bound in any way to type "real". There is no type in
> Fortran
> | such as "kind_specifier_of_real". Perhaps there should be, but now it's
> | probably too late as that would break existing code unless some *new*
> | inquiry functions were added to the language that returned enumerators
> of
> | the proper "type". (Sorry about that!)
>
> There's no need whatsoever for anything like that.
>
> All that is required is for vendors to use different kind numbers
> for EVERY kind type.
>
> This is perfectly permissible, since the kind numbers are entirely
> arbitrary.
>
> Thus, the problem could be solved virtually immediately.

OK. But I don't think the language standards will ever be written at that
level of detail. [smile].

--- e


From: baf on
On 3/12/2010 2:00 AM, m wrote:
> On Mar 12, 6:00 am, baf<b...(a)nowhere.com> wrote:
>>
>>
>
> Notice that the compiler can help you:
>
> gfortran -Wconversion test.f90 -o test
> test.f90:4.24:
>
> real(dp),parameter::a=1_dp,b=2_dp,c=a/b,d=1_dp/2_dp
> 1
> Warning: Conversion from INTEGER(8) to REAL(8) at (1)
> test.f90:4.31:
>
> real(dp),parameter::a=1_dp,b=2_dp,c=a/b,d=1_dp/2_dp
> 1
> Warning: Conversion from INTEGER(8) to REAL(8) at (1)
> test.f90:4.44:
>
> real(dp),parameter::a=1_dp,b=2_dp,c=a/b,d=1_dp/2_dp
> 1
> Warning: Conversion from INTEGER(8) to REAL(8) at (1)
>
>
> Marco


A gfortran compiler flag I had not discovered. Thanks!