[PATCH]: Integrate gfortran with MPC

Steve Kargl sgk@troutmask.apl.washington.edu
Wed May 20 07:40:00 GMT 2009


On Wed, May 20, 2009 at 12:14:01AM -0400, Kaveh R. GHAZI wrote:
> On Tue, 19 May 2009, Steve Kargl wrote:
> 
> > > > Okay for mainline?
> > > >
> > > OK. Thanks for your MPFR/MPC work!
> >
> > No.  The patch may not be correct, but I
> > haven't had time to review it.
> >
> > In particular, Kaveh uses mpfr_get_default_prec to
> > set the precision.  I believe this should be
> > mpfr_get_prec(re or im) depending on Fortran mix
> > mode rules.
> 
> I did that on purpose.  When I looked through the fortran frontend, it
> appeared that the code sets the default mpfr precision to 128 in arith.c
> and all of fortran's mpfr_t variables are initialized using the default
> precision via mpfr_init(), i.e. not mpfr_init2().
> 
> Note: In particular, the existing hand-rolled mpfr code in there uses
> mpfr_init() which uses the default precision for the intermediate
> variables used in the calculations.
> 
> MPC has no default initializer, you have to pass in some precision.  So
> that's why I pulled out the default mpfr precision.  It should match
> whatever precision of the mpfr_t variables that were passed in.
> 
> If that's not the right thing to do, just let me know what you'd prefer
> and I'll change it.  For the intermediate mpc_t variable, I can use the
> precision of the input re/im, or that of the result re/im, or the larger
> of the two.  Whatever you think makes sense.  If the precision of the real
> can be different than that of the imaginary part, let me know also.
> Otherwise I'll assume they are the same.
> 

Kaveh,

I'm at a conference and can't get to this until at least
the weekend.  I think that you may have misread the code.
The 128 in arith.c is only used for determining the inquiry
values of the INTEGER type.  In gfc_arith_init_1, there
are 2 loops the first loop deals with INTEGER, the second
deals with REAL.  In the second loop, you'll find a call
to gfc_set_model_kind(real_info->kind).  This sets the
default precision to the precision of the current REAL type.
The inquiry values are then determined for the current REAL
type (ie., HUGE(), DIGITS(), etc.).  If you spend time
reading both arith.c and simplify.c, you'll see that
gfortran correctly sets the precision to the required
precision with either gfc_set_model_kind() or gfc_set_model().

Elsewhere you've stated that gfortran's constant folding
of some complex-valued intrinsic functions is less accurate
than mpc.  I think you may be mistaken, unless mpfr is broken,
because the 128 has deceived you.

-- 
Steve



More information about the Gcc-patches mailing list