Re: Logicals converted to integers during reading
- From: "James Giles" <jamesgiles@xxxxxxxxxxxxxxxx>
- Date: Fri, 28 Jul 2006 23:20:38 GMT
There are several advantages of "all bits on" being .true.
and "all bits off" being .false. For example:
i = merge(j, k, cond)
If the internal representation of COND is already "all on"
or "all off" then there are machines where the above is a
single instruction.
Of course, in many (if not most) uses of the LOGICAL
data type, no canonical representation is ever produced.
The implementation performs a computationally equivalent
sequence of operations that works "as-if" the logical values
were computed fully. For example:
if (i==0 .and. j<0) then
On an x86 machine, the flags register after the first compare
(or other operation that sets the flags based on the value of i)
is 32 bits: only one of which (the zero flag) is of interest. But
why shift it around and/or mask that flag out? Similarly, the
flags register after the second compare (or other operation
that sets the flags based on j) is 32 bits: only one of which
(the sign flag) is of interest. You take those 32 bit flags register
images, shift one relative to the other so the flags you're interested
in line up, AND them together, and only then do you mask out the
result (and you still don't shift it down so that its value - interpreted
as an integer - is one). The result of all that will be "all off"
for .false. and "one bit on (somewhre)" for .true. And you
can already base a jump instruction directly on such an outcome.
As for the subject of this thread: I think that a conversion of
LOGICAL to/from INTEGER (if it exists at all) should be defined
to be:
INT(aLogical) == -1 ! if aLogical is .true.
INT(aLogical) == 0 ! if aLogical is .false.
! (positive zero, if there's a difference)
LOGICAL(anInt) == .true. ! if anInt is not (positive) zero
LOGICAL(anInt) == .false. ! if anInt is (positive) zero
Those should be the definitions regardless of whether 2's-
or 1's-complement, or even signed-magnitude is used for
the integers.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
.
- Follow-Ups:
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Re: Logicals converted to integers during reading
- From: James Giles
- Re: Logicals converted to integers during reading
- References:
- Logicals converted to integers during reading
- From: Bálint Aradi
- Re: Logicals converted to integers during reading
- From: Steve Lionel
- Re: Logicals converted to integers during reading
- From: beliavsky
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Re: Logicals converted to integers during reading
- From: Craig Powers
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Re: Logicals converted to integers during reading
- From: James Giles
- Re: Logicals converted to integers during reading
- From: glen herrmannsfeldt
- Logicals converted to integers during reading
- Prev by Date: Re: find a Fortran teacher
- Next by Date: Re: DFPORT
- Previous by thread: Re: Logicals converted to integers during reading
- Next by thread: Re: Logicals converted to integers during reading
- Index(es):
Relevant Pages
|