Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Writing double to file using C++ stream

0 views
Skip to first unread message

Christophe Bourez

unread,
Oct 17, 2002, 5:50:03 AM10/17/02
to
Dear all,

1. I 'd like to write (using operator<<) a double to file such that, when I
read it back (using operator>>), I get exactly the same value (no loss of
precision)
2. When 1 is solved, is it a way to write only needed digits (not to
trailing 0's). For example: 1.23456E-2 and, not 1.234560000000000E-2

Thank you,

Christophe Bourez

Pete Becker

unread,
Oct 17, 2002, 9:01:31 AM10/17/02
to
Christophe Bourez wrote:
>
> 1. I 'd like to write (using operator<<) a double to file such that, when I
> read it back (using operator>>), I get exactly the same value (no loss of
> precision)

Download copies of dtoa.c and g_fmt.c from
http://netlib.bell-labs.com/netlib/fp/index.html, then spend about a
week understanding how they do what they do. It's not easy.

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

0 new messages