logical*4 and logical*8?
Author Message
logical*4 and logical*8?

Hello,

I have absolutely no doubt that this is an absolutely silly question,
but here goes:

It seems to me that the point of LOGICAL variables is to store data of
a binary nature; i.e. a LOGICAL variable is either .true. or .false.
From the vantage point of my rather limited and largely self-taught
programming background, it would seem that a LOGICAL*8 variable wastes
at least 7 bytes on storing such information, if not 63 bits.

What am I missing? Why would one want to use LOGICAL*2, LOGICAL*4 or
LOGICAL*8, when it seems a LOGICAL*1 will do pretty much everything
the others will?

TIA,

matt.

Matthew C Roberts
Assistant Professor
Agricutural, Environmental, and Development Economics
The Ohio State University
email: ROBERTS dot 628 at OSU dot EDU

Tue, 16 Mar 2004 09:36:29 GMT
logical*4 and logical*8?

Quote:
> What am I missing? Why would one want to use LOGICAL*2, LOGICAL*4 or
> LOGICAL*8, when it seems a LOGICAL*1 will do pretty much everything
> the others will?

Most fortran variants do supply logical*1, logical*2 and logical*4.
Very few supply logical*8.

Consider the following code:

real*4 vdy (1000)
integer*4 ivdy (1000)
logical*4 lvdy (1000)
equivalence (vdy (1), ivdy (1), lvdy (1))

You can now use the above three vaiables interchangably.  Admittedly
not much use until you start suballocating the 1000 words of space.
Then, it becomes very usefull to have logical*4 (or *8).

Lynn McGuire

Tue, 16 Mar 2004 11:45:55 GMT
logical*4 and logical*8?

Quote:
> programming background, it would seem that a LOGICAL*8 variable wastes
> at least 7 bytes on storing such information, if not 63 bits.

It does.  Even logical*1 wastes 7/8 of its storage.

Quote:

> What am I missing? Why would one want to use LOGICAL*2, LOGICAL*4 or
> LOGICAL*8, when it seems a LOGICAL*1 will do pretty much everything
> the others will?

They don't fit into data structures the same way.  On a machine
with a 32-bit word (typical PC these days) logical*4 is more efficient
because it can be retrieved, processed, and stored in single operations,
without extracting just the significant bit.

However, if you are storing a black and white image (bitmap), you don't
want to use an array of logical*8 :-)

VAX VMS logicals were great in that they really only used one bit.
They carried extra bits of padding, but the values of those bits never
mattered.

Tue, 16 Mar 2004 12:08:31 GMT
logical*4 and logical*8?

Quote:

> I have absolutely no doubt that this is an absolutely silly question,

Actually it is a very good question.

Quote:
> What am I missing? Why would one want to use LOGICAL*2, LOGICAL*4 or
> LOGICAL*8, when it seems a LOGICAL*1 will do pretty much everything
> the others will?

You are missing the fact that, from at least Fortran-66 onwards,
real/integer/logical data types are defined to be ONE 'numeric storage
unit' in size.  (Complex and double precision are obviously defined to
occupy two NSUs.)

This allows a feature of Fortran called 'storage association' - allowing
EQUIVALENCE, multiple definitions of a common block, and mismatched
caller/callee argument types/ranks to work in a well-defined, if perhaps
dubious, fashion.

Two notes:

1.) Fortran-77 introduced the character data type.  However there is no
Standard-defined relationship between a character storage unit and a numeric
storage unit.  So, for example, EQUIVALENCEing a character variable to a
numeric variable is non-standard.

2.) In Fortran-90/95, numerical storage units/storage association is only
defined for default kinds and a non-interface-checked Fortran-77 calling
style.  Depending on storage association in general is frowned upon (but is
still, occasionally, a way to get certain things done in an efficient manner.)

Walt
-...-
Walt Spector

Tue, 16 Mar 2004 21:49:24 GMT
logical*4 and logical*8?

Quote:

>VAX VMS logicals were great in that they really only used one bit.
>They carried extra bits of padding, but the values of those bits never
>mattered.

Not so!  Every bit mattered.  Consider the program

LOGICAL P
INTEGER I
P = 7
I = P
PRINT *, I, P
END

VMS Fortran would print

7 T

It wouldn't do that if only the low-order bit were used.

Sincerely,
Bob Corbett

Wed, 17 Mar 2004 09:29:21 GMT
logical*4 and logical*8?

Quote:

> >VAX VMS logicals were great in that they really only used one bit.
> >They carried extra bits of padding, but the values of those bits never
> >mattered.
> Not so!  Every bit mattered.  Consider the program

>       LOGICAL P
>       INTEGER I
>       P = 7
>       I = P
>       PRINT *, I, P
>       END

> VMS Fortran would print

>        7 T

> It wouldn't do that if only the low-order bit were used.

Yes, it would.  The OpenVMS convention is that the low bit determines the
logical value - low bit 0 is false, low bit 1 is true - the other bits are
ignored.  This was designed into the OpenVMS standard for condition codes
(return statuses) which had four severity levels - 0 was warning, 1 was
success, 2 was error (non-fatal), 3 was informational and 4 was severe error
(5, 6 and 7 were reserved).  The VAX (and Alpha) architectures had
instructions for doing low-bit comparisons to make testing true/false easy.

Of course, all of this is invisible unless you try treating LOGICAL values
as INTEGER, or vice versa, which is non-portable, as many users have
discovered.

Compaq Visual Fortran uses this method by default, but it also supports the
C-style zero/non-zero test with the option /fpscomp:logicals.

--

Steve Lionel
Compaq Fortran Engineering
Intel Corporation
Nashua, NH

Compaq Fortran - http://www.compaq.com/fortran
Intel Fortran - http://developer.intel.com/software/products/compilers/f50/

Wed, 17 Mar 2004 20:49:10 GMT
logical*4 and logical*8?

Quote:

>> >VAX VMS logicals were great in that they really only used one bit.
>> >They carried extra bits of padding, but the values of those bits never
>> >mattered.

>> Not so!  Every bit mattered.  Consider the program

>>       LOGICAL P
>>       INTEGER I
>>       P = 7
>>       I = P
>>       PRINT *, I, P
>>       END

>> VMS Fortran would print

>>        7 T

>> It wouldn't do that if only the low-order bit were used.

>Yes, it would.

No it wouldn't.  It most be using some bits other than the low-order
bit to represent the value 7.

Quote:
>The OpenVMS convention is that the low bit determines the
>logical value - low bit 0 is false, low bit 1 is true - the other bits are
>ignored.  This was designed into the OpenVMS standard for condition codes
>(return statuses) which had four severity levels - 0 was warning, 1 was
>success, 2 was error (non-fatal), 3 was informational and 4 was severe error
>(5, 6 and 7 were reserved).  The VAX (and Alpha) architectures had
>instructions for doing low-bit comparisons to make testing true/false easy.

>Of course, all of this is invisible unless you try treating LOGICAL values
>as INTEGER, or vice versa, which is non-portable, as many users have
>discovered.

Since DEC, Compaq, Intel, possible Visual, possibly not, Fortran does
let users treat LOGICALs as INTEGERs, it requires using all the bits,
which is what I asserted.  This misfeature is near (though not at) the
top of the list of Fortran extensions I wish I did not have to support.

Sincerely,
Bob Corbett

Thu, 18 Mar 2004 15:08:27 GMT
logical*4 and logical*8?

Quote:
> >>       LOGICAL P
> >>       INTEGER I
> >>       P = 7
> >>       I = P
> >>       PRINT *, I, P
> >>       END

> >> VMS Fortran would print

> >>        7 T

> >> It wouldn't do that if only the low-order bit were used.

> >Yes, it would.

> No it wouldn't.  It most be using some bits other than the low-order
> bit to represent the value 7.

The binary representation of decimal 7 is "0...0111", so the low-order
bit would be set.

\$.02 -Ron Shepard

Fri, 19 Mar 2004 00:33:02 GMT
logical*4 and logical*8?

| >> >
| >> >VAX VMS logicals were great in that they really only used one bit.
| >> >They carried extra bits of padding, but the values of those bits never
| >> >mattered.
| >
| >> Not so!  Every bit mattered.  Consider the program
| >>
| >>       LOGICAL P
| >>       INTEGER I
| >>       P = 7
| >>       I = P
| >>       PRINT *, I, P
| >>       END
| >>
| >> VMS Fortran would print
| >>
| >>        7 T
| >>
| >> It wouldn't do that if only the low-order bit were used.
| >
| >Yes, it would.
|
| No it wouldn't.  It most be using some bits other than the low-order
| bit to represent the value 7.

No, you misinterpreted it. P carries its 0111 bit pattern all the time,
since P = 7 means exactly that, not P = IAND(7, 1). So, I = P *does* mean
I = 7. If P were 8 , the output would be.

8  F

However, I admit I prefer C-style use, since this one can lead to some
behaviours quite unexpected for the unawared.

Jugoslav
________________________
www.geocities.com/jdujic

Fri, 19 Mar 2004 16:01:45 GMT
logical*4 and logical*8?

Quote:

> >> >VAX VMS logicals were great in that they really only used one bit.
> >> >They carried extra bits of padding, but the values of those bits never
> >> >mattered.

> >> Not so!  Every bit mattered.
> >> It wouldn't do that if only the low-order bit were used.

> >Yes, it would.

> No it wouldn't.  It most be using some bits other than the low-order
> bit to represent the value 7.

Are you trying hard to miss the point?  The "padding" bits don't
matter for the logical value (T/F) of a logical variable.  Nobody
said they were zero.  You assign 7 to the variable, it doesn't
get converted to some special "boolean value" (typically -1 or 1
for true) exactly BECAUSE the high bits don't matter.

Sat, 20 Mar 2004 01:39:03 GMT

 Page 1 of 1 [ 10 post ]

Relevant Pages