public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "fxcoudert at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/52413] Incorrect behavior of FRACTION when applied to a constant
Date: Sun, 23 Jun 2013 12:29:00 -0000	[thread overview]
Message-ID: <bug-52413-4-J6xMOAsIPS@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-52413-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52413

--- Comment #6 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
The current patch is also lacking handling of the sign if signed zero is used.
This should do the trick:


   if (mpfr_sgn (x->value.real) == 0)
     {
-      mpfr_set_ui (result->value.real, 0, GFC_RND_MODE);
+      mpfr_set (result->value.real, x->value.real, GFC_RND_MODE);
       return result;
     }


Using mpfr_frexp() is a good idea, and probably a gain in the long term (easier
maintenance), so we may wrap it inside version checks. Tentative patch:


Index: simplify.c
===================================================================
--- simplify.c    (revision 200350)
+++ simplify.c    (working copy)
@@ -2342,16 +2342,25 @@ gfc_expr *
 gfc_simplify_fraction (gfc_expr *x)
 {
   gfc_expr *result;
+
+#if MPFR_VERSION < MPFR_VERSION_NUM(3,1,0)
   mpfr_t absv, exp, pow2;
+#else
+  mpfr_exp_t e;
+#endif

   if (x->expr_type != EXPR_CONSTANT)
     return NULL;

   result = gfc_get_constant_expr (BT_REAL, x->ts.kind, &x->where);

+#if MPFR_VERSION < MPFR_VERSION_NUM(3,1,0)
+
+  /* MPFR versions before 3.1.0 do not include mpfr_frexp.  */
+
   if (mpfr_sgn (x->value.real) == 0)
     {
-      mpfr_set_ui (result->value.real, 0, GFC_RND_MODE);
+      mpfr_set (result->value.real, x->value.real, GFC_RND_MODE);
       return result;
     }

@@ -2369,9 +2378,17 @@ gfc_simplify_fraction (gfc_expr *x)
   mpfr_ui_pow (pow2, 2, exp, GFC_RND_MODE);

   mpfr_div (result->value.real, absv, pow2, GFC_RND_MODE);
+  mpfr_copysign (result->value.real, result->value.real,
+         x->value.real, GFC_RND_MODE);

   mpfr_clears (exp, absv, pow2, NULL);

+#else
+
+  mpfr_frexp (&e, result->value.real, x->value.real, GFC_RND_MODE);
+
+#endif
+
   return range_check (result, "FRACTION");
 }



However, I don't have a machine set up for bootstrapping (and regtesting) this
change. I just happened to pass by here :)


  parent reply	other threads:[~2013-06-23 12:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28  9:39 [Bug libfortran/52413] New: " frouet at enseeiht dot fr
2012-02-28 16:13 ` [Bug libfortran/52413] " kargl at gcc dot gnu.org
2012-02-28 20:50 ` anlauf at gmx dot de
2013-06-22 12:58 ` [Bug fortran/52413] " dominiq at lps dot ens.fr
2013-06-22 15:31 ` sgk at troutmask dot apl.washington.edu
2013-06-23 12:29 ` fxcoudert at gcc dot gnu.org [this message]
2013-06-23 12:30 ` fxcoudert at gcc dot gnu.org
2013-06-23 13:15 ` dominiq at lps dot ens.fr
2013-06-23 14:11 ` fxcoudert at gcc dot gnu.org
2013-06-23 15:35 ` dominiq at lps dot ens.fr
2013-06-23 15:36 ` dominiq at lps dot ens.fr
2013-06-23 15:43 ` fxcoudert at gcc dot gnu.org
2013-06-23 16:10 ` dominiq at lps dot ens.fr
2013-06-24  8:45 ` burnus at gcc dot gnu.org
2013-06-24  8:45 ` burnus 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-52413-4-J6xMOAsIPS@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).