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 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 because -0 has the upper bit set only
which cannot be done using memset.

Thanks,
Andrew Pinski


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