[fortran PATCH] Implement a(:,:) = 0.0 using memset (take 2)

Steve Kargl sgk@troutmask.apl.washington.edu
Tue Dec 19 03:11:00 GMT 2006


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

There is a new mpfr_zero_p function for comparison to zero, but
I have investigated its semantics.
-- 
Steve



More information about the Fortran mailing list