This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: [fortran PATCH] Implement a(:,:) = 0.0 using memset (take 2)


On Mon, Dec 18, 2006 at 10:24:46PM -0500, Andrew Pinski wrote:
> > 
> > On Mon, Dec 18, 2006 at 09:46:35PM -0500, Andrew Pinski wrote:
> > > > 
> > > > +     case BT_REAL:
> > > > +       return mpfr_sgn (expr->value.real) == 0;
> > > 
> > > How well does the above handle -0's?
> > > 
> > 
> > It handles it as you would expect, and gfortran has depended
> > on this behavior for a long time.
> > 
> > #include <stdio.h>
> > #include <gmp.h>
> > #include <mpfr.h>
> > 
> > int main(void) {
> >   mpfr_t z;
> >   mpfr_init(z);
> >   mpfr_set_ui(z, 0, GMP_RNDN);
> >   mpfr_out_str(stdout, 10, 0, z, GMP_RNDN); printf("\n");
> >   if (mpfr_sgn(z) == 0) printf("zero\n");
> >   mpfr_neg(z,z,GMP_RNDN);
> >   mpfr_out_str(stdout, 10, 0, z, GMP_RNDN); printf("\n");
> >   if (mpfr_sgn(z) == 0) printf("zero\n");
> >   return 0;
> > }
> > % gcc -o z a.c -I/usr/local/include -L/usr/local/lib -lmpfr -lgmp
> > % ./z
> > 0
> > zero
> > -0
> > zero
> 
> Except -0 should not be done using memset so really we are handling
> it incorrectly :).
> The reason why I say we should not handle -0 with memset is becausei
> -0 has the upper bit set only
> which cannot be done using memset.
> 

Fortran does not distinguish between 0 from -0 with one exception

   The real type includes a zero value.  Processors that distinguish between
   positive and negative zeros shall treat them as equivalent
      (1) in all relational operations,
      (2) as actual arguments to intrinsic procedures other than SIGN, and
      (3) as the scalar-numeric-expr in an arithmetic IF.

If you combine (1) and (2), -0 is of no value (pun intended).
Without the IEEE 754 intrinsic module, one can't tell if a value is 
0 or -0.

-- 
Steve


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