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: Getting equivalent 'double' parsing in c++ and fortran?


Convey, Christian J CIV NUWC NWPT wrote:

The two programs printed out these numbers to stdout.  (The ellipses
didn't appear in the actual output.  They show where I didn't want to
type any more numerals.) :

2.70000000000000017762568294... (c++) 2.70000000000000017762570000... (fortran)


Assuming that the two programs really are using two different double-precision numbers to record "2.7", does anyone know what I can do to the C++ code so that, when parsing strings to doubles, it will get the same double-precision number that the fortran code yields?

Those two decimal strings represent the same binary number. gfortran's library uses an algorithm which will print the shortest string of non-zero digits that will exactly represent the binary number, that's why it stops where your C library doesn't.


Hope this helps,
- Tobi


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