[PATCH FORTRAN]: Use mpc_t for representing complex numbers
Tobias Burnus
burnus@net-b.de
Fri Jun 19 06:14:00 GMT 2009
Kaveh R. GHAZI wrote:
> Tested on x86_64-unknown-linux-gnu with and without MPC, no fortran
> regressions.
>
> Okay for mainline?
>
Yes, the patch is okay; for some small remarks see below. Thanks for the
patch.
> {
> rc = ARITH_DIV0;
> break;
> }
>
> - gfc_set_model (op1->value.complex.r);
> +
> + gfc_set_model (mpc_realref (op1->value.complex))
You are adding another empty line; I think one should be enough.
> static void
> complex_reciprocal (gfc_expr *op)
> {
> + gfc_set_model (mpc_realref (op->value.complex));
> +#ifdef HAVE_mpc
> + mpc_ui_div (op->value.complex, 1, op->value.complex, GFC_MPC_RND_MODE);
> +#else
>
I am wondering whether instead of keeping the "complex_reciprocal"
function, one should simply put "mpc_ui_div" into "arith_power", which
is the only user of that static function. (The question is what is
better: Calling a tiny static function with an obvious name and only
"op" arguments or to have the actual call. I leave this to you)
> /* x = base */
> +#ifdef HAVE_mpc
> + mpfr_set (x_r, mpc_realref (base->value.complex), GFC_RND_MODE);
> + mpfr_set (x_i, mpc_imagref (base->value.complex), GFC_RND_MODE);
> +#else
> mpfr_set (x_r, base->value.complex.r, GFC_RND_MODE);
> mpfr_set (x_i, base->value.complex.i, GFC_RND_MODE);
> +#endif
>
Here, the #else block is not needed as the #if block works for both.
> @@ -931,7 +994,6 @@ complex_pow (gfc_expr *result, gfc_expr
> mpfr_clears (x_r, x_i, tmp, re, im, NULL);
> }
>
> -
> /* Raise a number to a power. */
>
> static arith
>
I think the extra line can stay, having two empty lines before a new
function it more readable.
> static int
> compare_complex (gfc_expr *op1, gfc_expr *op2)
> {
> +#ifdef HAVE_mpc
> + return mpc_cmp (op1->value.complex, op2->value.complex) == 0;
> +#else
> return (mpfr_equal_p (op1->value.complex.r, op2->value.complex.r)
> && mpfr_equal_p (op1->value.complex.i, op2->value.complex.i));
> +#endif
> }
>
This would be also a candidate for moving to the two callers, but it can
equally well stay a separate function.
> - return encode_complex (source->ts.kind, source->value.complex.r,
> - source->value.complex.i, buffer, buffer_size);
> + return encode_complex (source->ts.kind,
> + mpc_realref (source->value.complex),
> + mpc_imagref (source->value.complex),
> + buffer, buffer_size);
>
I would change the prototype of encode_complex to accepting mpc_t.
Tobias
More information about the Fortran
mailing list