This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: single to double conversion


Richard E Maine <Richard.Maine@nasa.gov> wrote on Wed, 27 Sep 2006:
On Sep 27, 2006, at 12:35 PM, Steve Kargl wrote:

The author of g77 made the decide to use the f2c runtime library.
f2c always promotes a single precision function to double
precision.

I don't see an obvious way to do that and still conform to the Fortran standard. Perhaps I am missing a trick. Or perhaps g77 just fails to conform to the Fortran standard there. Having a compiler switch to enable a nonconforming behavior is one thing. But having a compiler that did not even have the option to conform to the standard strikes me as.... um.... problematic.

The nonconformance might not show up in most codes, but it sure isn't
hard to come up with a case of valid Fortran code that would fail under
such an implementation.  Consider

call sub(f(x))

where f(x) returns a (single precision) real, and sub has a (single
precision) real dummy argument. If f(x) is implemented to return a
double instead of a single, then its result isn't going to be valid as
an actual argument for sub. But if sub is separately compiled, there
won't be an opportunity for the compiler to detect or fix the problem.

Perhaps I'm misunderstanding what was going on here, but I'm at least a
little suspicious that you've just described a way in which g77
violates the standard (which is different from extending it).

This will probably work with g77, though I can't verify this at them moment.


g77 has this convention because the result is returned in a register, which is double precision. Now if this result is passed to a function, this will be done by reference, which means that it will have to be stored in memory first. The value will be reduced to single precision there.

g77 doesn't make default real function double precisions, as I unprecisely said before, its calling convention merely makes no difference between the two. If one wants to be sure that one uses REAL*4 everywhere one expects this to be the case, one may use the -fno-f2c command line switch.

- Tobi


---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]