public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/66864 -- Use the right precision in FLOOR()
@ 2015-07-14 20:03 Steve Kargl
  2015-07-14 21:20 ` Janne Blomqvist
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Kargl @ 2015-07-14 20:03 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 566 bytes --]

The attached patch fixes an issue in the constant 
folding of FLOOR().  In the old code, the precision
of an temporary MPFR variable was set according to
the requested kind of the INTEGER result, ie., the
wrong precision.  The patch sets the precision to
the precision of the arg of FLOOR().  Regression
tested on trunk.  OK to commit.

2015-07-14  Steven G. Kargl  <kargl@gcc.gnu.org>

	* simplify.c (gfc_simplify_floor): Set precision of temporary to
	that of arg.

2015-07-14  Steven G. Kargl  <kargl@gcc.gnu.org>

	gfortran.dg/pr66864.f90: New test.


-- 
Steve

[-- Attachment #2: pr66864.diff --]
[-- Type: text/x-diff, Size: 1214 bytes --]

Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c	(revision 225784)
+++ gcc/fortran/simplify.c	(working copy)
@@ -2351,9 +2351,7 @@ gfc_simplify_floor (gfc_expr *e, gfc_exp
   if (e->expr_type != EXPR_CONSTANT)
     return NULL;
 
-  gfc_set_model_kind (kind);
-
-  mpfr_init (floor);
+  mpfr_init2 (floor, mpfr_get_prec (e->value.real));
   mpfr_floor (floor, e->value.real);
 
   result = gfc_get_constant_expr (BT_INTEGER, kind, &e->where);
Index: gcc/testsuite/gfortran.dg/pr66864.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr66864.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/pr66864.f90	(working copy)
@@ -0,0 +1,16 @@
+! { dg-do run }
+! PR fortran/66864
+!
+program t
+   implicit none
+   real(8) x
+   x = 2.0d0**26.5d0
+   if (floor(x) /= 94906265) call abort
+   if (floor(2.0d0**26.5d0)/= 94906265) call abort
+   x = 777666555.6d0
+   if (floor(x) /= 777666555) call abort
+   if (floor(777666555.6d0) /= 777666555) call abort
+   x = 2000111222.6d0
+   if (floor(x) /= 2000111222) call abort
+   if (floor(2000111222.6d0) /= 2000111222) call abort
+end program t

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR fortran/66864 -- Use the right precision in FLOOR()
  2015-07-14 20:03 [PATCH] PR fortran/66864 -- Use the right precision in FLOOR() Steve Kargl
@ 2015-07-14 21:20 ` Janne Blomqvist
  0 siblings, 0 replies; 2+ messages in thread
From: Janne Blomqvist @ 2015-07-14 21:20 UTC (permalink / raw)
  To: Steve Kargl; +Cc: Fortran List, GCC Patches

On Tue, Jul 14, 2015 at 10:20 PM, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> The attached patch fixes an issue in the constant
> folding of FLOOR().  In the old code, the precision
> of an temporary MPFR variable was set according to
> the requested kind of the INTEGER result, ie., the
> wrong precision.  The patch sets the precision to
> the precision of the arg of FLOOR().  Regression
> tested on trunk.  OK to commit.
>
> 2015-07-14  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>         * simplify.c (gfc_simplify_floor): Set precision of temporary to
>         that of arg.
>
> 2015-07-14  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>         gfortran.dg/pr66864.f90: New test.
>
>
> --
> Steve

Ok, thanks.

-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-14 20:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-14 20:03 [PATCH] PR fortran/66864 -- Use the right precision in FLOOR() Steve Kargl
2015-07-14 21:20 ` Janne Blomqvist

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).