public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR32083 - Use correct sign for -Inf in real.c's mpfr_from_real
@ 2007-05-26 22:37 Tobias Burnus
  2007-05-26 23:40 ` Steve Kargl
  2007-05-27  8:21 ` Brooks Moses
  0 siblings, 2 replies; 5+ messages in thread
From: Tobias Burnus @ 2007-05-26 22:37 UTC (permalink / raw)
  To: gcc-patches, 'fortran@gcc.gnu.org'

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

:ADDPATCH middle-end:

This should be obvious. REAL_VALUE_TYPE's sign is one for negative
numbers and zero for positive numbers.
mpfr_set_inf is positive for sign >= 0, and negative for sign < 0.

Build on x86_64-unknown-linux-gnu and checked via check-gcc and
check-gfortran with no new failures.
(failing are gcc.c-torture/execute/mayalias-2.c (ICE),
gcc.c-torture/execute/mayalias-3.c (ICE) and gcc.dg/cpp/Wmissingdirs.c)

Ok for the trunk?

Tobias

[-- Attachment #2: real.diff --]
[-- Type: text/x-patch, Size: 2660 bytes --]

2007-05-26  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32083
	* real.c (mpfr_from_real): Fix sign of -Inf.

2007-05-26  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32083
	* gfortran.dg/transfer_simplify_3.f90: New.

Index: real.c
===================================================================
--- real.c	(revision 125096)
+++ real.c	(working copy)
@@ -4746,7 +4746,7 @@ mpfr_from_real (mpfr_ptr m, const REAL_V
   /* Take care of Infinity and NaN.  */
   if (r->cl == rvc_inf)
     {
-      mpfr_set_inf (m, r->sign);
+      mpfr_set_inf (m, r->sign == 1 ? -1 : 1);
       return;
     }
   
Index: testsuite/gfortran.dg/transfer_simplify_3.f90
===================================================================
--- testsuite/gfortran.dg/transfer_simplify_3.f90	(revision 0)
+++ testsuite/gfortran.dg/transfer_simplify_3.f90	(revision 0)
@@ -0,0 +1,53 @@
+! { dg-do run }
+! { dg-option "-fno-range-check" }
+! PR fortran/32083
+!
+! Test transfers of +Inf and -Inf
+! Testcase contributed by Jos de Kloe <kloedej@knmi.nl>
+!
+
+PROGRAM TestInfinite
+  IMPLICIT NONE
+  integer, parameter :: i8_ = Selected_Int_Kind(18)  ! = integer*8
+  integer, parameter :: r8_ = Selected_Real_Kind(15,307)  ! = real*8
+
+  integer(i8_), parameter :: bit_pattern_PosInf_i8_p = 9218868437227405312_i8_
+  integer(i8_), parameter :: bit_pattern_NegInf_i8_p = -4503599627370496_i8_
+
+  integer(i8_) :: bit_pattern_PosInf_i8 = 9218868437227405312_i8_
+  integer(i8_) :: bit_pattern_NegInf_i8 = -4503599627370496_i8_
+
+  integer(i8_) :: bit_pattern_PosInf_i8_hex
+  integer(i8_) :: bit_pattern_NegInf_i8_hex
+
+  integer(i8_) :: i
+  real(r8_)    :: r
+
+  data bit_pattern_PosInf_i8_hex /z'7FF0000000000000'/
+  !data bit_pattern_NegInf_i8_hex /z'FFF0000000000000'/
+  ! not portable, replaced by:
+  bit_pattern_NegInf_i8_hex = ibset(bit_pattern_PosInf_i8_hex,63)
+
+  if (bit_pattern_NegInf_i8_hex /= bit_pattern_NegInf_i8) call abort()
+  if (bit_pattern_PosInf_i8_hex /= bit_pattern_PosInf_i8) call abort()
+
+  r = transfer(bit_pattern_PosInf_i8,r)
+  if (r /= 1.0_r8_/0.0_r8_) call abort()
+  i = transfer(r,i)
+  if (bit_pattern_PosInf_i8 /= i) call abort()  
+
+  r = transfer(bit_pattern_NegInf_i8,r)
+  if (r /= -1.0_r8_/0.0_r8_) call abort()
+  i = transfer(r,i)
+  if (bit_pattern_NegInf_i8 /= i) call abort()
+
+  r = transfer(bit_pattern_PosInf_i8_p,r)
+  if (r /= 1.0_r8_/0.0_r8_) call abort()
+  i = transfer(r,i)
+  if (bit_pattern_PosInf_i8_p /= i) call abort()
+
+  r = transfer(bit_pattern_NegInf_i8_p,r)
+  if (r /= -1.0_r8_/0.0_r8_) call abort()
+  i = transfer(r,i)
+  if (bit_pattern_NegInf_i8_p /= i) call abort()
+END PROGRAM TestInfinite

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

* Re: PR32083 - Use correct sign for -Inf in real.c's mpfr_from_real
  2007-05-26 22:37 PR32083 - Use correct sign for -Inf in real.c's mpfr_from_real Tobias Burnus
@ 2007-05-26 23:40 ` Steve Kargl
  2007-05-27  8:21 ` Brooks Moses
  1 sibling, 0 replies; 5+ messages in thread
From: Steve Kargl @ 2007-05-26 23:40 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, 'fortran@gcc.gnu.org'

On Sat, May 26, 2007 at 11:55:39PM +0200, Tobias Burnus wrote:
> :ADDPATCH middle-end:
> 
> This should be obvious. REAL_VALUE_TYPE's sign is one for negative
> numbers and zero for positive numbers.
> mpfr_set_inf is positive for sign >= 0, and negative for sign < 0.
> 
> Build on x86_64-unknown-linux-gnu and checked via check-gcc and
> check-gfortran with no new failures.
> (failing are gcc.c-torture/execute/mayalias-2.c (ICE),
> gcc.c-torture/execute/mayalias-3.c (ICE) and gcc.dg/cpp/Wmissingdirs.c)
> 
> Ok for the trunk?
> 

OK.


-- 
Steve

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

* Re: PR32083 - Use correct sign for -Inf in real.c's mpfr_from_real
  2007-05-26 22:37 PR32083 - Use correct sign for -Inf in real.c's mpfr_from_real Tobias Burnus
  2007-05-26 23:40 ` Steve Kargl
@ 2007-05-27  8:21 ` Brooks Moses
  2007-05-27  8:39   ` Tobias Burnus
  1 sibling, 1 reply; 5+ messages in thread
From: Brooks Moses @ 2007-05-27  8:21 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, 'fortran@gcc.gnu.org'

Tobias Burnus wrote:
> This should be obvious. REAL_VALUE_TYPE's sign is one for negative
> numbers and zero for positive numbers.
> mpfr_set_inf is positive for sign >= 0, and negative for sign < 0.
[...]
> 2007-05-26  Tobias Burnus  <burnus@net-b.de>
> 
> 	PR fortran/32083
> 	* gfortran.dg/transfer_simplify_3.f90: New.
> 
> Index: real.c
> ===================================================================
> --- real.c	(revision 125096)
> +++ real.c	(working copy)
> @@ -4746,7 +4746,7 @@ mpfr_from_real (mpfr_ptr m, const REAL_V
>    /* Take care of Infinity and NaN.  */
>    if (r->cl == rvc_inf)
>      {
> -      mpfr_set_inf (m, r->sign);
> +      mpfr_set_inf (m, r->sign == 1 ? -1 : 1);
>        return;
>      }

Argh!  Obviously that's my fault -- thanks for tracking it down.

It looks like all of the other uses of "sign" in real.c leave off the 
"== 1", and just have "r->sign ? -1 : 1", so this should probably be 
changed to that form.

I'm obviously not a middle-end maintainer, but I _did_ write the code in 
question, and this correction seems obvious to me, so I think it's okay 
to commit on that basis.

(Also, for the record, this particular piece of code is not used by 
anything other than the Fortran front end, so there won't be a C or C++ 
testcase to exercise the correction.)

- Brooks

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

* Re: PR32083 - Use correct sign for -Inf in real.c's mpfr_from_real
  2007-05-27  8:21 ` Brooks Moses
@ 2007-05-27  8:39   ` Tobias Burnus
  2007-05-27 10:56     ` Brooks Moses
  0 siblings, 1 reply; 5+ messages in thread
From: Tobias Burnus @ 2007-05-27  8:39 UTC (permalink / raw)
  To: Brooks Moses, gcc-patches, 'fortran@gcc.gnu.org'

Brooks Moses schrieb:
>> +      mpfr_set_inf (m, r->sign == 1 ? -1 : 1);
> It looks like all of the other uses of "sign" in real.c leave off the
> "== 1", and just have "r->sign ? -1 : 1", so this should probably be
> changed to that form.
I think the other are ok and this is the only place where
REAL_VALUE_TYPE and mpfr are used in the same command. As long as one
has only REAL_VALUE_TYPE's signs or only mpfr signs, one remains consistent.

(The other place where mpfr and REAL_VALUE_TYPE are used together is
real_from_mpfr, but that one is ok:
      if (mpfr_sgn (m) < 0)
        *r = REAL_VALUE_NEGATE (*r);
)

> I'm obviously not a middle-end maintainer, but I _did_ write the code
> in question, and this correction seems obvious to me, so I think it's
> okay to commit on that basis.
I committed it now as obvious (r125108).

Tobias

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

* Re: PR32083 - Use correct sign for -Inf in real.c's mpfr_from_real
  2007-05-27  8:39   ` Tobias Burnus
@ 2007-05-27 10:56     ` Brooks Moses
  0 siblings, 0 replies; 5+ messages in thread
From: Brooks Moses @ 2007-05-27 10:56 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, 'fortran@gcc.gnu.org'

Tobias Burnus wrote:
> Brooks Moses schrieb:
>>> +      mpfr_set_inf (m, r->sign == 1 ? -1 : 1);
>> It looks like all of the other uses of "sign" in real.c leave off the
>> "== 1", and just have "r->sign ? -1 : 1", so this should probably be
>> changed to that form.
> 
> I think the other are ok and this is the only place where
> REAL_VALUE_TYPE and mpfr are used in the same command. As long as one
> has only REAL_VALUE_TYPE's signs or only mpfr signs, one remains consistent.

I think I must have been unclear.  I was not objecting to what your code 
was doing, merely to how you wrote it, and the part I was talking about 
has nothing at all to do with MPFR....

All I'm saying is that that line should be written as

       mpfr_set_inf (m, r->sign ? -1 : 1);

in order to be consistent with how r->sign is tested in the other places 
in real.c where it is tested.  The effect should be the same; it's just 
a stylistic choice.

- Brooks

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

end of thread, other threads:[~2007-05-27  8:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-26 22:37 PR32083 - Use correct sign for -Inf in real.c's mpfr_from_real Tobias Burnus
2007-05-26 23:40 ` Steve Kargl
2007-05-27  8:21 ` Brooks Moses
2007-05-27  8:39   ` Tobias Burnus
2007-05-27 10:56     ` Brooks Moses

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