This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch,Fortran] PR33197 (F2008) Add complex tan/cosh/sinh/cosh
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: Tobias Burnus <burnus at net-b dot de>
- Cc: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org, "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Thu, 9 Jul 2009 15:11:53 -0700
- Subject: Re: [Patch,Fortran] PR33197 (F2008) Add complex tan/cosh/sinh/cosh
- References: <20090709190816.GA12639@net-b.de> <20090709214613.GA59599@troutmask.apl.washington.edu>
On Thu, Jul 09, 2009 at 02:46:13PM -0700, Steve Kargl wrote:
> On Thu, Jul 09, 2009 at 09:08:16PM +0200, Tobias Burnus wrote:
> > Hi all,
> >
> > as Kaveh pointed out: The complex trigonometric
> > functions tan, sinh, cosh and tanh are supported by
> > MPC and libgfortran has the C99 fallback functions
> > implemented. Thus one can simply enable them,
> > what this patch does.
> >
> > I have not added the compile-time simplification
> > via MPC - leaving this to a later patch by Kaveh,
> > me or someone else.
> >
> > Build and regtested on x86-64-linux.
> > OK for the trunk?
> >
>
> FX said he had a small amount of time to look into
> implementing these functions. Perhaps, he'll do the
> simplification.
>
> It appears that the c99_function.c fallback functions
> need some scrutiny. Your complex_intrinsic_3.f90
> fails on FreeBSD. A quick scan of c99_functions.c
> finds
>
> ccoshf (float complex a)
> {
> float r, i;
> float complex v;
>
> r = REALPART (a);
> i = IMAGPART (a);
> COMPLEX_ASSIGN (v, coshf (r) * cosf (i), - (sinhf (r) * sinf (i)));
> return v;
> }
>
> The sign of the imaginary part is wrong. It should be +.
> Likewise, in ccosh and ccoshl.
>
Of the functions I scanned, the following diff should fix
wrong identities.
--
Steve
Index: c99_functions.c
===================================================================
--- c99_functions.c (revision 149287)
+++ c99_functions.c (working copy)
@@ -1165,7 +1165,7 @@ csinhl (long double complex a)
#endif
-/* cosh(a + i b) = cosh(a) cos(b) - i sinh(a) sin(b) */
+/* cosh(a + i b) = cosh(a) cos(b) + i sinh(a) sin(b) */
#if !defined(HAVE_CCOSHF)
#define HAVE_CCOSHF 1
float complex
@@ -1176,7 +1176,7 @@ ccoshf (float complex a)
r = REALPART (a);
i = IMAGPART (a);
- COMPLEX_ASSIGN (v, coshf (r) * cosf (i), - (sinhf (r) * sinf (i)));
+ COMPLEX_ASSIGN (v, coshf (r) * cosf (i), sinhf (r) * sinf (i));
return v;
}
#endif
@@ -1191,7 +1191,7 @@ ccosh (double complex a)
r = REALPART (a);
i = IMAGPART (a);
- COMPLEX_ASSIGN (v, cosh (r) * cos (i), - (sinh (r) * sin (i)));
+ COMPLEX_ASSIGN (v, cosh (r) * cos (i), sinh (r) * sin (i));
return v;
}
#endif
@@ -1206,13 +1206,13 @@ ccoshl (long double complex a)
r = REALPART (a);
i = IMAGPART (a);
- COMPLEX_ASSIGN (v, coshl (r) * cosl (i), - (sinhl (r) * sinl (i)));
+ COMPLEX_ASSIGN (v, coshl (r) * cosl (i), sinhl (r) * sinl (i));
return v;
}
#endif
-/* tanh(a + i b) = (tanh(a) + i tan(b)) / (1 - i tanh(a) tan(b)) */
+/* tanh(a + i b) = (tanh(a) + i tan(b)) / (1 + i tanh(a) tan(b)) */
#if !defined(HAVE_CTANHF)
#define HAVE_CTANHF 1
float complex
@@ -1224,7 +1224,7 @@ ctanhf (float complex a)
rt = tanhf (REALPART (a));
it = tanf (IMAGPART (a));
COMPLEX_ASSIGN (n, rt, it);
- COMPLEX_ASSIGN (d, 1, - (rt * it));
+ COMPLEX_ASSIGN (d, 1, rt * it);
return n / d;
}
@@ -1241,7 +1241,7 @@ ctanh (double complex a)
rt = tanh (REALPART (a));
it = tan (IMAGPART (a));
COMPLEX_ASSIGN (n, rt, it);
- COMPLEX_ASSIGN (d, 1, - (rt * it));
+ COMPLEX_ASSIGN (d, 1, rt * it);
return n / d;
}
@@ -1258,7 +1258,7 @@ ctanhl (long double complex a)
rt = tanhl (REALPART (a));
it = tanl (IMAGPART (a));
COMPLEX_ASSIGN (n, rt, it);
- COMPLEX_ASSIGN (d, 1, - (rt * it));
+ COMPLEX_ASSIGN (d, 1, rt * it);
return n / d;
}