> Gerry Ford wrote:
>> There's a lot to learn and comment on here. If I understand Richard
>> correctly, the second number in the selected real kind invocation is to
>> accomodate a real of size 10** your input. By making these numbers
>> intentionally different, I think you could confuse a good compiler.
>> Heck, it confuses me.
>>
>> I used the debugger to figure out what type my machine was giving me.
>> Instead of having to track this information down in a debugger, can you
>> make an implementation tell you the type of any given variable? It looks
>> like the real * power of 2 type declaration works here.
>
> I don't think you mean the "type".
I don't have my fortranspeak disambiguated from C in all realms. My
knowledge of C isn't all it should be either (I'm blaming the jerks in clc
for that). I guess what I meant was what the implementation thinks the
variable is. I'm cooking up another little program that can illustrate:
integer, parameter :: sp = selected_real_kind(3,3)
integer, parameter :: dp = selected_real_kind(15,30)
real (kind=dp):: estimate, directrix, generatrix, radius
real (kind=sp):: vol, base, height, theta
directrix = 25.0
vol = 50.0
base = 3.14159*7.0**2
print *, "base is ", base
height = (1.0_dp/3.0_dp) * base *vol
print *, "height is ", height
end
When I go in with the debugger to look at my variables, I see that base and
height have differing widths. Does a person say that one is of kind real *4
while the other is of kind real *8? We know to associate the integer one to
the one variety and two to the other.
I always think an image helps:
http://zaxfuuq.net/fortran196914.jpg
>That's obvious from the
> declaration of the variable. If you want to know the properties of
> a number, look at the precision and range intrinsics (and maybe the
> kind).
> print *, range(1), range(1.0), range(1.0d0)
> etc, with kind and precision (there's no integer precision)
>
> For real numbers precision and range are two different and unrelated
> concepts. The SELECTED_REAL_KIND(precision,range) intrinsic
> lets you specify either or both of what you need. The problem with
> understanding them is that existing machines only support a couple
> of versions of real numbers. So, there isn't much practical
> variation in what different values of precision or range you
> can specify. But, there is no contradiction in asking for a
> precision of 20 decimal digits and an exponent range of 20
> (meaning zero and at least 10**(-20) through 10**20).
>
> Try the program from before with something like
> do I = 1,1000,25
> print *, I, selected_int_kind(range=i)
> enddo
> and you'll see that the kind value changes slowly and compare
> that with the results of the prints from 15 lines above.
I'll do all this when I next have machine time. Thanks for your reply,
Dick. BTW, am I correct to think that the sign intrinsic returns negative
one if unequal and one if both positive or both negative?
--
"That this social order with its pauperism, famines, prisons, gallows,
armies, and wars is necessary to society; that still greater disaster
would ensue if this organization were destroyed; all this is said only
by those who profit by this organization, while those who suffer from it
- and they are ten times as numerous - think and say quite the contrary."
~~ Leo Tolstoy