single to double conversion
Tobias Schlüter
tobias.schlueter@physik.uni-muenchen.de
Wed Sep 27 20:06:00 GMT 2006
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.
More information about the Fortran
mailing list