From owner-freebsd-standards@FreeBSD.ORG Sun Oct 16 16:30:23 2005 Return-Path: X-Original-To: freebsd-standards@hub.freebsd.org Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C6B3A16A41F for ; Sun, 16 Oct 2005 16:30:23 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7CA8543D49 for ; Sun, 16 Oct 2005 16:30:23 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j9GGUNAO062840 for ; Sun, 16 Oct 2005 16:30:23 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j9GGUNxZ062839; Sun, 16 Oct 2005 16:30:23 GMT (envelope-from gnats) Date: Sun, 16 Oct 2005 16:30:23 GMT Message-Id: <200510161630.j9GGUNxZ062839@freefall.freebsd.org> To: freebsd-standards@FreeBSD.org From: Sergey Matveychuk Cc: Subject: Re: standards/85090: [patch] add memalign() and posix_memalign() functions X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Sergey Matveychuk List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Oct 2005 16:30:23 -0000 The following reply was made to PR standards/85090; it has been noted by GNATS. From: Sergey Matveychuk To: bug-followup@FreeBSD.org, sem@FreeBSD.org, stefanf@FreeBSD.org Cc: Subject: Re: standards/85090: [patch] add memalign() and posix_memalign() functions Date: Sun, 16 Oct 2005 20:22:12 +0400 This is a multi-part message in MIME format. --------------020009040200090906070000 Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit I've removed memalign() and made some fixes on a man page. -- Sem. --------------020009040200090906070000 Content-Type: text/plain; name="posix_memalign.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="posix_memalign.patch" Index: include/stdlib.h =================================================================== RCS file: /home/ncvs/src/include/stdlib.h,v retrieving revision 1.58 diff -u -r1.58 stdlib.h --- include/stdlib.h 12 Sep 2005 15:58:15 -0000 1.58 +++ include/stdlib.h 16 Oct 2005 12:43:30 -0000 @@ -157,7 +157,7 @@ * research can be done. */ #if __POSIX_VISIBLE /* >= ??? */ -/* int posix_memalign(void **, size_t, size_t); (ADV) */ +int posix_memalign(void **, size_t, size_t); /* (ADV) */ int rand_r(unsigned *); /* (TSF) */ int setenv(const char *, const char *, int); void unsetenv(const char *); Index: lib/libc/stdlib/Makefile.inc =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/Makefile.inc,v retrieving revision 1.48 diff -u -r1.48 Makefile.inc --- lib/libc/stdlib/Makefile.inc 12 May 2004 08:13:40 -0000 1.48 +++ lib/libc/stdlib/Makefile.inc 16 Oct 2005 12:43:30 -0000 @@ -41,5 +41,5 @@ MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3 strtol.3 strtoimax.3 MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 strtoul.3 strtoumax.3 MLINKS+=malloc.3 calloc.3 malloc.3 free.3 malloc.3 malloc.conf.5 \ - malloc.3 realloc.3 malloc.3 reallocf.3 + malloc.3 realloc.3 malloc.3 reallocf.3 malloc.3 posix_memalign.3 MLINKS+=tsearch.3 tdelete.3 tsearch.3 tfind.3 tsearch.3 twalk.3 Index: lib/libc/stdlib/malloc.3 =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/malloc.3,v retrieving revision 1.63 diff -u -r1.63 malloc.3 --- lib/libc/stdlib/malloc.3 20 Jan 2005 09:17:04 -0000 1.63 +++ lib/libc/stdlib/malloc.3 16 Oct 2005 12:43:30 -0000 @@ -36,11 +36,11 @@ .\" @(#)malloc.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.63 2005/01/20 09:17:04 ru Exp $ .\" -.Dd August 19, 2004 +.Dd October 16, 2005 .Dt MALLOC 3 .Os .Sh NAME -.Nm malloc , calloc , realloc , free , reallocf +.Nm malloc , calloc , realloc , free , reallocf , posix_memalign .Nd general purpose memory allocation functions .Sh LIBRARY .Lb libc @@ -54,6 +54,8 @@ .Fn realloc "void *ptr" "size_t size" .Ft void * .Fn reallocf "void *ptr" "size_t size" +.Ft int +.Fn posix_memalign "void **ptr" "size_t alignment" "size_t size" .Ft void .Fn free "void *ptr" .Ft const char * @@ -148,6 +150,19 @@ for realloc causing memory leaks in libraries. .Pp The +.Fn posix_memalign +function allocates +.Fa size +bytes aligned on a boundary specified by +.Fa alignment +and places the address of the allocated memory in +.Fa ptr . +The value of +.Fa alignment +must be a power of two and a multiple of +.Fn sizeof "void *" . +.Pp +The .Fn free function causes the allocated memory referenced by .Fa ptr @@ -276,6 +291,18 @@ .Er ENOMEM . .Pp The +.Fn posix_memalign +function returns zero on success, +.Er EINVAL +if the +.Fa alignment +parameter was not a power of two, or was not a multiple of +.Fn sizeof "void *" . +Note that +.Va errno +is not set. +.Pp +The .Fn realloc and .Fn reallocf @@ -363,7 +390,8 @@ If .Fn malloc , .Fn calloc , -.Fn realloc +.Fn realloc , +.Fn posix_memalign or .Fn free detect an error or warning condition, @@ -480,6 +508,11 @@ .Fn free functions conform to .St -isoC . +.Pp +The +.Fn posix_memalign +function conforms to +.St -p1003.1-2001 . .Sh HISTORY The present allocation implementation started out as a file system for a drum attached to a 20bit binary challenged computer which was built @@ -493,8 +526,18 @@ .Fn reallocf function first appeared in .Fx 3.0 . +.Pp +The +.Fn posix_memalign +function first appeared in +.Fx 7.0 . .Sh AUTHORS .An Poul-Henning Kamp Aq phk@FreeBSD.org +.Pp +The +.Fn posix_memalign +function was added by +.An Sergey Matveychuk Aq sem@FreeBSD.org .Sh BUGS The messages printed in case of problems provide no detail about the actual values. Index: lib/libc/stdlib/malloc.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/malloc.c,v retrieving revision 1.90 diff -u -r1.90 malloc.c --- lib/libc/stdlib/malloc.c 27 Feb 2005 17:16:16 -0000 1.90 +++ lib/libc/stdlib/malloc.c 16 Oct 2005 12:43:30 -0000 @@ -1164,3 +1164,25 @@ return (pubrealloc(ptr, size, " in realloc():")); } +#define POWEROF2(x) ((((x)-1)&(x))==0) + +int +posix_memalign(void **ptr, size_t alignment, size_t size) +{ + void *p1; + int err; + + if (alignment % sizeof(void *) || !POWEROF2(alignment)) + return(EINVAL); + + p1 = pubrealloc(NULL, (size+alignment-1) & ~(alignment-1), + " in posix_memalign():"); + if(p1) { + *ptr = p1; + return (0); + } else { + err = errno; + errno = 0; + return (err); + } +} --------------020009040200090906070000-- From owner-freebsd-standards@FreeBSD.ORG Sun Oct 16 18:41:40 2005 Return-Path: X-Original-To: freebsd-standards@FreeBSD.org Delivered-To: freebsd-standards@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8D50916A41F for ; Sun, 16 Oct 2005 18:41:40 +0000 (GMT) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.208.78.105]) by mx1.FreeBSD.org (Postfix) with ESMTP id 187A543D48 for ; Sun, 16 Oct 2005 18:41:40 +0000 (GMT) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.13.4/8.13.4) with ESMTP id j9GIfYan024772; Sun, 16 Oct 2005 11:41:34 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.13.4/8.13.1/Submit) id j9GIfTkk024771; Sun, 16 Oct 2005 11:41:29 -0700 (PDT) (envelope-from sgk) Date: Sun, 16 Oct 2005 11:41:29 -0700 From: Steve Kargl To: Bruce Evans Message-ID: <20051016184129.GA24651@troutmask.apl.washington.edu> References: <20051002191841.GA40568@troutmask.apl.washington.edu> <20051004164618.U47262@delplex.bde.org> <20051005032400.GA6736@troutmask.apl.washington.edu> <20051005191936.N51036@delplex.bde.org> <20051006212602.GA40609@troutmask.apl.washington.edu> <20051007231439.F58005@delplex.bde.org> <20051007190239.GA78674@troutmask.apl.washington.edu> <20051008052850.S59139@delplex.bde.org> <20051010185153.GA55589@troutmask.apl.washington.edu> <20051012160109.I73531@delplex.bde.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="J/dobhs11T7y2rNN" Content-Disposition: inline In-Reply-To: <20051012160109.I73531@delplex.bde.org> User-Agent: Mutt/1.4.2.1i X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-standards@FreeBSD.org Subject: Re: complex.h math functions X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Oct 2005 18:41:40 -0000 --J/dobhs11T7y2rNN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 , 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 --J/dobhs11T7y2rNN-- From owner-freebsd-standards@FreeBSD.ORG Mon Oct 17 11:02:08 2005 Return-Path: X-Original-To: freebsd-standards@freebsd.org Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6B61216A42D for ; Mon, 17 Oct 2005 11:02:08 +0000 (GMT) (envelope-from owner-bugmaster@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id E6C1D43D4C for ; Mon, 17 Oct 2005 11:02:07 +0000 (GMT) (envelope-from owner-bugmaster@freebsd.org) Received: from freefall.freebsd.org (peter@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j9HB27NY022535 for ; Mon, 17 Oct 2005 11:02:07 GMT (envelope-from owner-bugmaster@freebsd.org) Received: (from peter@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j9HB2712022529 for freebsd-standards@freebsd.org; Mon, 17 Oct 2005 11:02:07 GMT (envelope-from owner-bugmaster@freebsd.org) Date: Mon, 17 Oct 2005 11:02:07 GMT Message-Id: <200510171102.j9HB2712022529@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: peter set sender to owner-bugmaster@freebsd.org using -f From: FreeBSD bugmaster To: freebsd-standards@FreeBSD.org Cc: Subject: Current problem reports assigned to you X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Oct 2005 11:02:09 -0000 Current FreeBSD problem reports Critical problems Serious problems S Submitted Tracker Resp. Description ------------------------------------------------------------------------------- o [2001/03/05] bin/25542 standards /bin/sh: null char in quoted string o [2002/12/13] kern/46239 standards posix semaphore implementation errors o [2003/04/21] standards/51209standards [PATCH] add a64l()/l64a/l64a_r functions o [2003/07/12] standards/54410standards one-true-awk not POSIX compliant (no exte o [2005/06/25] standards/82654standards C99 long double math functions are missin 5 problems total. Non-critical problems S Submitted Tracker Resp. Description ------------------------------------------------------------------------------- o [2000/09/24] bin/21519 standards sys/dir.h should be deprecated some more o [2001/01/16] bin/24390 standards Replacing old dir-symlinks when using /bi s [2001/01/24] standards/24590standards timezone function not compatible witn Sin s [2001/06/18] kern/28260 standards UIO_MAXIOV needs to be made public p [2001/11/20] standards/32126standards getopt(3) not Unix-98 conformant s [2002/03/19] standards/36076standards Implementation of POSIX fuser command o [2002/06/14] standards/39256standards snprintf/vsnprintf aren't POSIX-conforman p [2002/08/12] standards/41576standards POSIX compliance of ln(1) o [2002/10/23] standards/44425standards getcwd() succeeds even if current dir has o [2002/12/09] standards/46119standards Priority problems for SCHED_OTHER using p o [2002/12/21] standards/46441standards /bin/sh does not do parameter expansion i o [2003/07/25] standards/54833standards [pcvt] more pcvt deficits o [2003/07/25] standards/54839standards [pcvt] pcvt deficits o [2003/07/31] standards/55112standards glob.h, glob_t's gl_pathc should be "size o [2003/09/05] standards/56476standards cd9660 unicode support simple hack o [2003/10/29] standards/58676standards grantpt(3) alters storage used by ptsname s [2004/02/14] standards/62858standards malloc(0) not C99 compliant o [2004/03/29] kern/64875 standards [patch] add a system call: fdatasync() o [2004/05/07] standards/66357standards make POSIX conformance problem ('sh -e' & o [2004/05/11] standards/66531standards _gettemp uses a far smaller set of filena o [2004/08/22] standards/70813standards [PATCH] ls not Posix compliant o [2004/08/26] docs/70985 standards [patch] sh(1): incomplete documentation o o [2004/09/22] standards/72006standards floating point formating in non-C locales o [2005/03/20] standards/79055standards Add an IFS regression test for shells o [2005/03/20] standards/79056standards regex(3) regression tests o [2005/03/21] standards/79067standards /bin/sh should be more intelligent about a [2005/04/23] standards/80293standards sysconf() does not support well-defined u o [2005/05/20] standards/81287standards [PATCH]: fingerd(8) might send a line not o [2005/07/21] standards/83845standards [libm] [patch] add log2() and log2f() sup o [2005/08/18] standards/85080standards output of long double subnormals (with pr o [2005/08/18] standards/85090standards [patch] add memalign() and posix_memalign 31 problems total. From owner-freebsd-standards@FreeBSD.ORG Fri Oct 21 10:50:58 2005 Return-Path: X-Original-To: freebsd-standards@freebsd.org Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E79D516A41F for ; Fri, 21 Oct 2005 10:50:58 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailout1.pacific.net.au (mailout1.pacific.net.au [61.8.0.84]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1510243D45 for ; Fri, 21 Oct 2005 10:50:57 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout1.pacific.net.au (8.13.4/8.13.4/Debian-3) with ESMTP id j9LAouHk008223; Fri, 21 Oct 2005 20:50:56 +1000 Received: from epsplex.bde.org (katana.zip.com.au [61.8.7.246]) by mailproxy2.pacific.net.au (8.13.4/8.13.4/Debian-3) with ESMTP id j9LAoqDG014286; Fri, 21 Oct 2005 20:50:53 +1000 Date: Fri, 21 Oct 2005 20:50:53 +1000 (EST) From: Bruce Evans X-X-Sender: bde@epsplex.bde.org To: Steve Kargl In-Reply-To: <20051016184129.GA24651@troutmask.apl.washington.edu> Message-ID: <20051021194624.H598@epsplex.bde.org> References: <20051002191841.GA40568@troutmask.apl.washington.edu> <20051004164618.U47262@delplex.bde.org> <20051005032400.GA6736@troutmask.apl.washington.edu> <20051005191936.N51036@delplex.bde.org> <20051006212602.GA40609@troutmask.apl.washington.edu> <20051007231439.F58005@delplex.bde.org> <20051007190239.GA78674@troutmask.apl.washington.edu> <20051008052850.S59139@delplex.bde.org> <20051010185153.GA55589@troutmask.apl.washington.edu> <20051012160109.I73531@delplex.bde.org> <20051016184129.GA24651@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-standards@freebsd.org Subject: Re: complex.h math functions X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Oct 2005 10:50:59 -0000 On Sun, 16 Oct 2005, Steve Kargl wrote: > On Wed, Oct 12, 2005 at 05:23:28PM +1000, Bruce Evans wrote: > Hopefully, this new version is closer to KNF. It still has only 4 chars for all secondary indents >> 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. The current order is almost that in the standard. This order is not bad but it might not give the simplest or shortest classification. In particular, I think it might be better to group by 0's before grouping by Infs and NaNs. > This version incorporates your changes, fixes > a few more whitespace problems, and expands the > comments on the exceptional cases. I modified to to try to document all the sign combinations, and fixed a couple of bugs: % --- s_ccosh.c~ Mon Oct 17 12:11:18 2005 % +++ s_ccosh.c Tue Oct 18 18:11:22 2005 % @@ -63,9 +63,17 @@ % % /* % - * cosh(+0 + I Inf) = NaN +- I 0. The sign of 0 in the result % - * is unspecified. Raise the invalid floating-point exception. % + * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0. % + * The sign of 0 in the result is unspecified. Choice = normally % + * the same as dNaN. Raise the invalid floating-point exception. % * % - * cosh(+0 + I NaN) = NaN +- I 0. The sign of 0 in the result % - * is unspecified. % + * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0. % + * The sign of 0 in the result is unspecified. Choice = normally % + * the same as d(NaN). % + * % + * Say something about our sign choices generally but not specifically? % + * The above is specific; dNaN = default NaN and d(NaN) = input NaN % + * with default transformation under operations (e.g., on i386's, % + * convert signaling NaNs to quiet NaNs by setting the quiet bit). % + * XXX indentation of all of these. % */ % if ((ix | lx) == 0 && iy >= 0x7ff00000) This also says something about NaN not always being the same value. I'm not sure where this should be documented. Ther is another indentation problem in these comments. 2 spaces after the "*" is unusual, and is not useful since the same indentation is used for the formulas and the descriptions. I only changed the formatting to start a new line after the formulas. % @@ -73,9 +81,11 @@ % % /* % - * cosh(x + I Inf) = NaN + I NaN. Raise the invalid % + * cosh(x +- I Inf) = dNaN + I dNaN. % + * Raise the invalid % * floating-point exception for finite nonzero x. % * % - * cosh(x + I NaN) = NaN + I NaN. Optionally raise the invalid % - * floating-point exception for finite nonzero x. % + * cosh(x + I NaN) = d(NaN) + I d(NaN). % + * Optionally raises the invalid % + * floating-point exception for finite nonzero x. Choice = raise. % */ % if (ix < 0x7ff00000 && iy >= 0x7ff00000) An earlier version tried to document the sign of the resulting NaN. I decided that this was too much detail. But the detail that the sign of 0's is copied from the sign of a NaN is documented for other cases. This also improves the wording for options. % @@ -83,10 +93,13 @@ % % /* % - * cosh(+Inf + I 0) = +Inf + I 0. % - * cosh(+Inf + I NaN) = +Inf + I NaN. % - * cosh(+Inf + I y) = +Inf cis(y) for finite nonzero y. % - * cis(y) = cos(y) + I sin(y). % - * cosh(+Inf + I Inf) = +Inf + I NaN. The sign of Inf in the result % - * is unspecified. Raise the invalid floating-point exception. % + * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0. % + * % + * cosh(+-Inf + I NaN) = +Inf + I d(NaN). % + * % + * cosh(+-Inf +- I Inf) = +Inf + I dNaN. % + * The sign of Inf in the result is unspecified. Choice = always +. % + * Raise the invalid floating-point exception. % + * % + * cosh(+-Inf + I y) = +Inf cos(y) +- I Inf sin(y) % */ % if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { This also adds newlines and drops cis(). cis() doesn't work in the precence of signs. % @@ -99,11 +112,14 @@ % % /* % - * cosh(NaN + I 0) = NaN +- I 0. The sign of 0 in the result % + * cosh(NaN +- I 0) = d(NaN) + I sign(d(NaN, +-0))0. % + * The sign of 0 in the result % * is unspecified. % * % - * cosh(NaN + I y) = NaN + I NaN. Raise the invalid % - * floating-point exception for finite nonzero y. % + * cosh(NaN + I y) = d(NaN) + I d(NaN). % + * Optionally raises the invalid % + * floating-point exception for finite or infinite nonzero y. % + * Choice = raise for infinite y only. % * % - * cosh(NaN + I NaN) = NaN + I NaN. % + * cosh(NaN + I NaN) = d(NaN) + I d(NaN). % */ % if ((iy | ly) == 0) This also fixes the description of the exception for cos(NaN + I y). I checked all your decriptions against n1124.pdf and got this fix from there. Note that the case cosh(NaN +- I Inf) is together with cosh(NaN + I y) for finite y since finite and infinite y's act the same here because the NaN dominates. Hmm, it seems wrong to even optionally raise an exception for finite y. > >> % 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. Exceptional cases are mostly not described at all for the real functions, so I wouldn't describe them better for the complex functions. I was thinking mainly of doumenting the intention that the error is < 2 ulps and noting cases where this isn't implemented in the BUGS section. >> % + * 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. I'd still like to find a more concise version. Have a look at e_pow.c. > I've updated [c_coshf.c] also. Note, the forward declaration of > ccosh() is not needed because complex.h should contain a > prototype for it. My version with these and some other cosmetic changes. Everything except the copyright: % /* % * Hyperbolic cosine of a float complex argument. % */ % % #include % % float complex % ccoshf(float complex z) % { % % return (ccosh(z)); % } >> % 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 , 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 actually used `complex'. _COMPLEX_H is much better. The only problem with it is to misspell it consistently (it should be spelled _COMPLEX_H_; tail -1 *.h in /usr/include shows similar misspellings and other style bugs like backwards comments in about half of the headers). >> 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 it is, after fixing the ifdef and removing most undercores: % Index: math_private.h % =================================================================== % RCS file: /home/ncvs/src/lib/msun/src/math_private.h,v % retrieving revision 1.17 % diff -u -2 -r1.17 math_private.h % --- math_private.h 4 Feb 2005 20:05:39 -0000 1.17 % +++ math_private.h 21 Oct 2005 10:43:22 -0000 % @@ -155,4 +162,45 @@ % } while (0) % % +#ifdef _COMPLEX_H % +/* % + * Inline functions that can be used to construct complex values. % + * % + * The C99 standard intends x+I*y to work for this, but x+I*y is % + * currently unusable in general since gcc introduces many overflow, % + * underflow, sign and efficiency bugs by rewriting I*y as (0+I)*(y+0*I) % + * and laboriously computing the full complex product. In particular, % + * I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted to 0+I*0. % + */ % +static __inline float complex % +cpackf(float x, float y) % +{ % + float complex z; % + % + __real__ z = x; % + __imag__ z = y; % + return (z); % +} % + % +static __inline double complex % +cpack(double x, double y) % +{ % + double complex z; % + % + __real__ z = x; % + __imag__ z = y; % + return (z); % +} % + % +static __inline long double complex % +cpackl(long double x, long double y) % +{ % + long double complex z; % + % + __real__ z = x; % + __imag__ z = y; % + return (z); % +} % +#endif /* _COMPLEX_H */ % + % /* % * ieee style elementary functions > 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); Use the version with the extra function call for now. Bruce