# Re: REAL -> string -> REAL

*From*: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>*Date*: Tue, 22 Jan 2008 10:29:19 -0800

Gus Gassmann wrote:

Having all sorts of problems in C/C++ with the conversion in the

subject line, I thought to try my luck in the Fortran forum.

The situation is this: I have a (large number of) floating point

number(s), let's assume in double precision --- this might be subject

to change --- that I have to write to a file in ASCII format (an XML

file, if that makes a difference) and subsequently read back in (into

the same type of real that I used before; I'll make sure of this

somehow).

Traditionally when you wanted to write out data and read in the

exact same data you used UNFORMATTED I/O.

For many years of Fortran there were many different floating point

representations that it didn't make sense to ask for same value

back again on a different system. Over the years, the default REAL

has varied from 36 bits, to 32, to 60, to 64, on different systems.

(Probably some others in there, too.)

Are there any tools available in Fortran that will allow me to do the

conversion from REAL (assume binary) to string (assume decimal) and

back to REAL _without_loss_of_precision_? (That is, I must be

guaranteed that the two versions of the real number have the same

internal representation. Side condition: I'd like to use the smallest

string representation that will give this guarantee.

You could do it in a loop, using internal I/O, write out the

value with different format widths in E format, and do binary

search to find the appropriate width. That may only guarantee it

using the same library, though. If I were doing this, I might

try for a base 16 system.

-- glen

.

**References**:**REAL -> string -> REAL***From:*Gus Gassmann

- Prev by Date:
**Re: REAL -> string -> REAL** - Next by Date:
**Re: TRANSFER on LOGICALs** - Previous by thread:
**Re: REAL -> string -> REAL** - Next by thread:
**Re: REAL -> string -> REAL** - Index(es):