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  2002

COMP-FORTRAN-90 2002

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Double precision constants

From:

Richard Maine <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Tue, 29 Oct 2002 09:44:13 -0800

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (105 lines)

Paddy O'Brien writes:

 > Isn't it
 > about time that the standard made it mandatory that the constant is
 > hoisted to the kind of the variable being assigned to, or in an
 > expression hoisted to the greatest precision in that expression.
 >
 > I cannot believe that this change will ever break any code, rather it
 > will do what we (and there seem to be many of us falling into this trap)
 > naive programmers thought that we were getting.

This has been discussed innumerable times before.  Part of the problem
is that there are cases where it is flatly impossible for the compiler
to infer the intended precision.  There are other cases where,
although it is possible, it is extremely obscure, confusing, and
inconsistent.  I'm a big fan of consistency and simplicity.  The
existing rules clearly aren't what everyone would intuit at first,
but they are simple and consistent, and thus not that difficult to
learn.  Anyone who can't learn them is going to be unable to even
come close to learning the complicated set of rules necessary to
determine exactly when you promote in all cases.

On the other hand, I do agree with the position expressed by
Dick (and by others, such as Giles on clf) that it would be good of
compilers to give warnings when they notice questionable cases.
I personally think it more helpful in the long run for
compilers to help the users notice the problem areas than to
try to quietly hide the issue by fixing upthe simple cases,
leaving the user completely unprepared to deal with the harder
ones because he is used to it all just working by magic.

> I'm pretty certain that hoisting is done within expressions for
 > variables, and believe it to be part of the standard.  My belief in this
 > respect may not be reality.

No, it is never done by the standard.  Some compilers try to "help"
out (see my diatribe above about such alleged help) by quietly
fixing such things, but the standard absolutely never specifies
this.  You are probably thinking of things like  x+y where x
and y are of different precisions.  The standard says that this
is done by converting the lower precision one to the higher
precision an dthen doing the addition.  However, there is nothing
special here about constants.  If you have, say  0.1d0+0.2,
then the 0.2 is a single precision constant.  It is converted to
double precision before the addition, but that is only *AFTER*
its single precision value is determined.  There are no cases
anywhere that the standard says to interpret 0.2 as a double
precision constant.  See my comment above about consistency.  If
you think the rules are complicated, then you don't know them.
Easy to make a mistake, yes - complicated, no.

A few trivial examples of problem cases.  I'm not going to spend
much time on this, so these are just off the top of my head.
I've been through this too many times before (and I'm home today,
just briefly checking my work email).

   double precision x
   x = f(0.2)

Should the 0.2 be promoted?  If your answer is yes, then you just
broke lots of existing code because f is a function that takes a
single precision argument.  If the answer is no, then we are starting
down the road to one of the many complications - namely, where exactly
is the line drawn.

Suppose f is a generic with both single and double precision versions.
Does that change the answer?   Or suppose it is generic and has only
one of those.  Suppose f is a strange but legal generic where the
specific with a single precision argument gives a double result,
and vise versa.  Yes, that would be strange, but us standards-writers
have to define all the possibilities, no matter how strange.

Once you have all the answers for user-written generics, how about
the intrinsic ones, such as

  x = sqrt(0.2)

I bet you are going to tell me that the 0.2 should be promoted in that
case.  If so, you are going to have a fun time explaining exactly
where the line got drawn between the cases where the 0.2 can't be
promoted and the cases where you want it to be.  And you need to
explain this not just to me, but to all those users who get confused
by the current simple rule.  Good luck.  Don't forget to cover user
extensions of intrinsic generics.  And defined assignments, just in
case you thought you could avoid trouble by giving up on things that
look like function arguments.  Oh, and if your answer is that the 0.2
is not promoted, you'll get to argue with lots of posters who have
said it should be.

This is all just one of the more "obvious" lines of complication,
and this is all off the top of my head.  It gets really, really
complicated.  I'm not at all sure that I am even capable of
coming up with a complete and consistent set of rules.  I'm
absolutely certain that any set of rules I could come up with
would be considered "wrong" by plenty of people.  And I'm also
certain that I couldn't explain them to the average Fortran
programmer.  I'd just have to summarize them as "sometimes
the compiler will fix things up for you; other times you'll be
screwed."

--
Richard Maine                |  Good judgment comes from experience;
[log in to unmask]   |  experience comes from bad judgment.
                             |        -- Mark Twain

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