public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jvdelisle at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/61847] bug in gfortran runtime: digits cut off when reading floating point number
Date: Tue, 22 Jul 2014 01:40:00 -0000	[thread overview]
Message-ID: <bug-61847-4-QeIHmLcF7X@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-61847-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61847

--- Comment #11 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
After all that has been said here, I am almost afraid to add any more.

This is not a bug.  Fortran and GFortran are not locale aware. The ',' or '.'
are read from the file or device literally as is.  From this read, a numeric
string is constructed.  If the unit was opened with decimal='comma' and a comma
was seen, the comma is converted to '.'.  If decimal='point' and a comma is
read, an error occurs.

After the above described numeric string is constructed it is passed to the
glibc library strtod (sring to double).  The glibc library is locale aware and
if the locale has defined the decimal token to be a ',' (comma), it see the
decimal 'point' and interprets it as end of string conversion.

We do not want to take a performance it by checking the locale setting on every
I/O operation, so the only logical place to do that is in main.c.  However, in
the example, the original poster is only compiling a gfortran subroutine. 
There is no gfortran program, so there is no gfortran main.c

So the responsibility for addressing the locale has to fall on the C program
side or within the users subroutine using maybe system calls that are
extensions and not Fortran standard code.  This users code would query the
current runtime environment for current decimal setting and then do the I/O
with the appropriate decimal= specifier.

To avoid confusion, remember that gfortran is reading the characters in the
file literally.  So if there is a 1,2345 it sees the comma.  If there is a
1.234 it sees the point. The conversion to internal floating point
representation occurs after the character data is read.

The easiest solution is to do what I said in in Comment #2 on the C side.  The
equivalent can be done on the fortran side as well, just not as easily.

One possible enhancement we could consider is providing some set and get locale
intrinsics.  This would be helpful for some folks. But, thats a lot more work.


  parent reply	other threads:[~2014-07-22  1:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-61847-4@http.gcc.gnu.org/bugzilla/>
2014-07-19  6:19 ` [Bug fortran/61847] bug in gfortran runtime on OSX: " jvdelisle at gcc dot gnu.org
2014-07-21 15:41 ` e2cd58e1 at opayq dot com
2014-07-21 17:50 ` kargl at gcc dot gnu.org
2014-07-21 17:55 ` e2cd58e1 at opayq dot com
2014-07-21 17:58 ` kargl at gcc dot gnu.org
2014-07-21 18:18 ` e2cd58e1 at opayq dot com
2014-07-21 18:26 ` sgk at troutmask dot apl.washington.edu
2014-07-21 18:33 ` e2cd58e1 at opayq dot com
2014-07-21 19:50 ` [Bug fortran/61847] bug in gfortran runtime: " dominiq at lps dot ens.fr
2014-07-22  1:40 ` jvdelisle at gcc dot gnu.org [this message]
2014-07-22  2:07 ` e2cd58e1 at opayq dot com
2014-07-22  3:29 ` jvdelisle at gcc dot gnu.org
2014-07-22  4:28 ` jvdelisle at gcc dot gnu.org
2014-07-22  4:46 ` sgk at troutmask dot apl.washington.edu
2014-07-25 22:04 ` jvdelisle at gcc dot gnu.org
2014-08-02 21:12 ` jvdelisle at gcc dot gnu.org
2014-08-19 20:50 ` jb at gcc dot gnu.org
2014-11-03 11:02 ` burnus at gcc dot gnu.org
2014-11-04 12:35 ` jb at gcc dot gnu.org
2014-11-05 10:51 ` jb at gcc dot gnu.org
2014-11-10  0:18 ` jb at gcc dot gnu.org
2014-11-10  0:21 ` jb at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-61847-4-QeIHmLcF7X@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).