Re: Logicals converted to integers during reading



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


.



Relevant Pages

  • Re: Logicals converted to integers during reading
    ... (or other operation that sets the flags based on the value of i) ... shift one relative to the other so the flags you're interested ... can already base a jump instruction directly on such an outcome. ... I believe some RISC machines have instructions that can do complicated ...
    (comp.lang.fortran)
  • Re: [PATCH] alternative to sys_indirect, part 1
    ... >> inherited across acceptso I doubt any user space software will be too ... >> upset by such a shift. ... no file descriptor flags are inherited. ...
    (Linux-Kernel)
  • Re: Einfache Bitmasking Frage
    ... Was willst Du denn mit dem Shift? ... Eigentlich testet man solche Flags _immer_ ohne Shift. ... '&&' ist ein boolescher Operator und kein Bit-Operator. ...
    (de.comp.lang.c)
  • Left shift operator (<<), why?
    ... The left shift operator, '<<', is used to shift the bits ... create what my colleagues and I call Flags. ... Also, please note that a single pipe, '|', is a bitwise ... > internal enum InterestLevel ...
    (microsoft.public.dotnet.languages.csharp)