Re: REAL -> string -> REAL



FX <coudert@xxxxxxxxxxxxx> wrote:

There is a paper by David Gay (c. 1990) in which he describes the
algorithm, but I have not been able to locate the C-code that goes with
it. What is the situation in the Fortran world? Do I have to write my
own implementation from scratch?

Most compilers should do what you describe (ie lossless I/O) when you use
the default format:

write (unit,*) my_real

even though I'm not too sure this is actually required by the Standard.

This is definitely not required by the standard. I might even argue that
the language of the standard hints more against than for this. The
standard requires that the field widths be selected to be "reasonable"
(or some such simillar term). If the standard wanted to specify lossless
conversion, it could have done that explicitly enough. Certainly
lossless conversion would be allowed as one definition of "reasonable",
but it is *NOT* required. My personal definition of "reasonable" would
be quite different, for example.

I most vehemently recommend against people depending on this one. That's
not what list-directed output is for. This is just variant number 42 of
the same fundamental problem with misuse of list-directed output.
List-directed output is for fast (to the programmer) and simple output
when you are not picky about the details. If you are picky about the
details, then don't use list-directed output. Those who ignore this
advice (or haven't heard or deduced it) are regularly comming here for
help when their expectations are not met.

Please do not encourage further people to make this mistake.

That some particular assumption about list-directed output might happen
to be true on some particular compilers isn't good enough.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.