From owner-freebsd-standards@FreeBSD.ORG Sat Nov 29 08:31:07 2003 Return-Path: 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 1963716A4CE for ; Sat, 29 Nov 2003 08:31:07 -0800 (PST) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.208.78.105]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0DA9A43FBF for ; Sat, 29 Nov 2003 08:31:06 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) hATGV58u036014 for ; Sat, 29 Nov 2003 08:31:05 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost)hATGV51Z036013 for freebsd-standards@FreeBSD.ORG; Sat, 29 Nov 2003 08:31:05 -0800 (PST) (envelope-from sgk) Date: Sat, 29 Nov 2003 08:31:05 -0800 From: Steve Kargl To: freebsd-standards@FreeBSD.ORG Message-ID: <20031129163105.GA32651@troutmask.apl.washington.edu> References: <20031129000133.GA30662@troutmask.apl.washington.edu> <20031129080911.GA25448@VARK.homeunix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031129080911.GA25448@VARK.homeunix.com> User-Agent: Mutt/1.4.1i Subject: Re: Implementing C99's roundf(), round(), and roundl() X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Nov 2003 16:31:07 -0000 On Sat, Nov 29, 2003 at 12:09:11AM -0800, David Schultz wrote: > On Fri, Nov 28, 2003, Steve Kargl wrote: > > Can the math functions round[fl]() be implemented in > > terms of other math(3) functions and still conform to the > > C99 and POSIX standard? For example, > > > > #include > > > > float roundf(float x) { > > float t; > > if (x >= 0.0) { > > t = ceilf(x); > > if ((t - x) > 0.5) t -= 1.0; > > return t; > > } else { > > t = ceilf(-x); > > if ((t + x) > 0.5) t -= 1.0; > > return -t; > > } > > } > > This looks correct to me at first glance, modulo possible problems > with overflow. It's valuable to have simple MI implementations of > these functions to avoid hampering efforts to port FreeBSD to new > architectures. Faster MD versions can always be added later. (I > noticed the other day that Intel has actually released an > optimized IA64 libm, which we should consider importing.) I don't undrestand your overflow comment. ceil[f]() can return Inf and nan, but in those cases round[f]() should also return Inf and nan. The two operations, (t-x) and (t+x), should yield a value in the range [0,1). I'll submit a PR with a man page. As a side comment, we need to start coding the missing C99 math(3) functions because GCC is moving to using these in their CVS development trees. -- Steve