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: [gccgo] Add complex numbers


On Thu, 11 Mar 2010, Ian Lance Taylor wrote:

> Richard Henderson <rth@redhat.com> writes:
>
> >> +    case OPERATOR_MULT:
> >> +      {
> >> +	// You might think that multiplying two complex numbers would
> >> +	// be simple, and you would be right, until you start to think
> >> +	// about getting the right answer for infinity.  If one
> >> +	// operand here is infinity and the other is anything other
> >> +	// than zero or NaN, then we are going to wind up subtracting
> >> +	// two infinity values.  That will give us a NaN, but the
> >> +	// correct answer is infinity.
> > ...
> >
> > We already require the mpc library.  Surely some of this
> > can be simplified...
>
> Probably.  I haven't looked into mpc at all yet.
> Ian

FWIW, I was able to convert the fortran frontend to use mpc_t for complex
numbers.  It was pretty simple, I just changed the expression type in
gfortran.h from a struct containing a pair of mpfr_t to a field of type
mpc_t.  Then see what broke when bootstrapping, repair and repeat.  It was
entirely a compile-time fixup.

I think it was easier because the fortran frontend used explicit
alloc/dealloc calls when necessary.  If garbage collection is involved
then it will be harder.  (Note mpfr_t and mpc_t both suffer from this via
GMP's memory alloc model.)

I had toyed with the idea of replacing all tree-based floating point stuff
with mpfr_t/mpc_t for all frontends and the middle-end.  This would solve
most (all?) of our accuracy problems.  E.g. see:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21718#c7

But I got stuck on the GC issues.

		--Kaveh

--- orig/egcc-SVN20100311/gcc/tree.h    2010-02-19 02:00:33.000000000
+0100
+++ egcc-SVN20100311/gcc/tree.h 2010-03-11 18:41:37.000000000 +0100
@@ -1396,7 +1396,7 @@ struct real_value;

 struct GTY(()) tree_real_cst {
   struct tree_common common;
-  struct real_value * real_cst_ptr;
+  mpfr_t real_cst_ptr;
 };

 /* In a FIXED_CST node.  */



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