JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  2005

COMP-FORTRAN-90 2005

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: LOGICAL (was: maxloc of a logical array)

From:

robin <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Tue, 29 Mar 2005 10:24:05 +1000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (121 lines)

> Date:          Sun, 27 Mar 2005 17:09:56 -0700
> From:          James Giles <[log in to unmask]>

> robin wrote:
> ...
> >> As correctly pointed out by another, the canonical representation
> >> and the testing method are somewhat independent.  Assuming two's
> >> complement integers, the canonical representation that travels best
> >> is -1 for true and 0 for false.
> >
> > No it's not.
> > 1.      Negative 1 presents problems when it is desired to convert
> >         logical to integer. Logical stored as 0 and 1 convert
> >         easily to numeric 0 and 1. [...]
>
> Logical stored as -1 and 0 easily converts to INTEGER -1 and 0.

Sure they can, but they are the wrong values.

> Your fallacious assumptions are still showing.

On the contrary, yours are.
The first flaw in yours is that 0 and -1 are best,
when in point of fact that is not the case.
Since the internal representation is not defined in Fortran,
manufacturers are going to use the scheme
that best suits the hardware.  That could well be 0 and 1,
or negative and positive, but not -1 and 0.

> > [...]   Which is what the orginal enquirer wanted to do.
>
> What he wanted was the first .true. value in an aray.

No, he wanted 0 and 1.

======================quote==================
Date sent:                Thu, 24 Mar 2005 08:15:34 +0800
From:                     Daniel and Nicola Grimwood

yes I was thinking in terms of 0 and 1.

Daniel.
=======================end quote===============
>  There is
> no need to make assuptions about the internal representation
> of LOGICALs to do that at all.

I have already pointed that out, and even suggested a solution
along those lines.

>  The language need not make
> such assumptions even possible.  It shouldn't.  At no time
> did the original person want to convert LOGICALs to INTEGERs.

He wanted to use the values 0 and 1. (see above).
The internal value is stored in an integer word.
It looks like an integer to me.
You even claimed (erroneously) that the best values would be -1 and 0.

Reasons 2 and 3 were omitted, so you have conceded that
they are valid arguments.

> >> 4.      A statement such as A = B .GT. C produces either positive,
> >         or negative, or zero, when B and C are subtracted.  If such
> >         a value were used as the logical result, that value would
> >         be neither negative 1 nor zero for most cases.
>
> The sign bit actually works much better than 1 vs. 0 in this case.

You mean much better than -1 and 0.

> The subtract (C-B) produces the sign bit (and, on the machines
> where it's relevant, the "negative" condition code).  The produced
> sign is the correct value for the logical predicate in question (negative
> means true, non-negative means false).

And then we get to strings.  Comparing strings does not
usually produce 0 and -1.  Typically, the outcome is/are
setting(s) in a condition code register or flag register.

> The bottom line is, and this is repeated information, the language
> doesn't specify what the internal representation of LOGICALs
> are.  It shouldn't.

That's a design error.  Corrected in PL/I.

With a defined representation, every Fortran compiler would
be consistent and programs could rely on the internal value,
and there would be some consistency in converting from
logical to numeric.
(BTW, the 'word' result harks from the days of word machines.)

>  On most hardware I have any interest in at
> all, neither implementation (-1 vs. 0 or 0 vs. 1) is produced
> directly be compare instructions.

Of course not.  It's sufficient to branch on >, >=, etc.
But in the case of multiple comparisons - e.g.,
        if ((a > b) & (b < c)) ...
that tends to become cumbersome, and the logicize instruction
is of help here (converting to 0 [=false] and 1 [true] ).

But having the 0/1 model comes to the fore with
character data, where a numeric result is not produced
by the hardware, being recorded only as flag(s) or condition code.
Having a consistent mechanism across all the data types
means that -1/0 falls flat, while 0/1 yields a sustainable
outcome.

>  In many cases that interest
> me, -1 vs. 0 is a better choice for the canonical internal rep
> than 1 v.s 0.  In an even larger set of interesting environments,
> interpreting *any* negative as .true. and *any* non-negative as
> .false. is even better.  Using the least significant bit is also the
> least interesting option.

But in practice, 0 and 1 provide the best outcome on many machines.

> --
> J. Giles

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

December 2023
February 2023
November 2022
September 2022
February 2022
January 2022
June 2021
November 2020
September 2020
June 2020
May 2020
April 2020
December 2019
October 2019
September 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager