complex.h math functions
Steve Kargl
sgk at troutmask.apl.washington.edu
Sun Oct 16 11:41:40 PDT 2005
On Wed, Oct 12, 2005 at 05:23:28PM +1000, Bruce Evans wrote:
> On Mon, 10 Oct 2005, Steve Kargl wrote:
>
> >I've attached the latest version. Hopefully, I caught the
> >rest of the style(9) problems. The cosh.3 man page has been
>
> No :-).
Hopefully, this new version is closer to KNF.
> >updated. I did not hook s_ccosh.c up to the Makefile
> >because I wasn't sure were to put it in msun/src. If you have
> >no further comments, can you commit this version (or your
> >simplified version)? I'll look at the other trigometric and
> >hyperbolic functions when we converge on s_ccosh.c.
>
> use it. Listing all the special cases also serves as documentation.
> I think the current order of special cases is not quite the best,
> however.
I don't follow why you think the special cases need to be re-order.
Without knowing how the user base will abuse ccosh, there should
be no prefered order.
> Patch relative to your last version:
This version incorporates your changes, fixes
a few more whitespace problems, and expands the
comments on the exceptional cases.
> % diff -ruN /usr/src/lib/msun/man/cosh.3 freebsd/src/lib/msun/man/cosh.3
> % --- /usr/src/lib/msun/man/cosh.3 Fri Jan 14 15:28:28 2005
> % +++ freebsd/src/lib/msun/man/cosh.3 Sat Oct 8 11:46:29 2005
> % ...
>
> OK; could be more detailed.
Do you want a section that describes the range of inputs that
return a non-infinite results? Do you want a section that
describes the return value and the exceptional cases? I'll
have to do this later because I'll need to learning some
additional mdoc features.
> Still has lots of strange indents -- corrupt tab above, 4-chars only for
> most second indents.
I'm not sure how these crept into the last version. I re-indented
the file, so hopefully this is fixed.
> % + * cosh(x + I Inf) = NaN + I NaN, finite x != 0, invalid exception.
> % + * cosh(x + I NaN) = NaN + I NaN, finite x != 0, opt. inval. except.
> % + */
>
> Not quite enough space to describe it all on 1 line; the inputs and outputs
> get mixed cryptically; might use more formal abbreviations.
I've expanded all comments to essentially the language in n1124.pdf.
> % + * cosh(+Inf + I y) = +Inf [cos(y) + I sin(y)], y != 0 and finite.
>
> Still have the strange brackets here.
It's a mathematical expression; not a KNF-ized C language construct.
However, I changed the comment to n1124.pdf's use of cis(y) and then
define cis(y) = cos(y) + I sin(y).
> % +float complex
> % +ccoshf(float complex z)
> % +{
> % + return ((float complex) ccosh((double complex) z));
> % +}
>
> I prefer to use implicit conversions.
I've updated this also. Note, the forward declaration of
ccosh() is not needed because complex.h should contain a
prototype for it.
> % diff -ruN /usr/src/lib/msun/src/math_private.h
> freebsd/src/lib/msun/src/math_private.h
> % --- /usr/src/lib/msun/src/math_private.h Fri Feb 4 12:05:39 2005
> % +++ freebsd/src/lib/msun/src/math_private.h Fri Oct 7 17:30:40 2005
> % @@ -155,6 +155,36 @@
> % } while (0)
> %
>
> I needed a namespace hack to make this compile. Clients that don't use
> this shouldn't need to include <complex.h>, and this file shouldn't
> include it. I used "#ifdef I".
A single letter #ifdef makes me nervous, and it isn't very descriptive.
I would suggest using #ifdef _COMPLEX_H. OTOH, math_private.h isn't
an installed header file, so only the person or persons writing the
complex math functions need to be bothered by this.
> I think the underscores shouldn't be used here (not even for __inline).
> This is not a public interface so we don't need to be very careful with
> the namespace.
I removed the underscores in my local tree. There, of course, were no problems.
> Otherwise good. These interfaces seem to work well.
You did not provide a patch to your local math_private.h.
> Here is my current "simpler" version. I plan to merge it into the
> other version when the other version's indentationis fixed.
See the new version.
BTW, the exceptional cases for ccos(z) are defined in n1124.pdf
in terms of ccos(z) = ccosh(I z). We can do
double complex
ccos(double complex z)
{
return (ccosh(-cimag(z),creal(z));
}
or if you prefer we can copy s_ccosh.c and change
x = creal(z);
y = cimag(z);
to
x = -cimag(z);
y = creal(x);
--
Steve
More information about the freebsd-standards
mailing list