From owner-freebsd-standards@FreeBSD.ORG Sat Nov 29 00:11:37 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 C9AFB16A4CE for ; Sat, 29 Nov 2003 00:11:37 -0800 (PST) Received: from VARK.homeunix.com (adsl-68-121-163-164.dsl.pltn13.pacbell.net [68.121.163.164]) by mx1.FreeBSD.org (Postfix) with ESMTP id B77A243F3F for ; Sat, 29 Nov 2003 00:11:36 -0800 (PST) (envelope-from das@FreeBSD.ORG) Received: from VARK.homeunix.com (localhost [127.0.0.1]) by VARK.homeunix.com (8.12.9/8.12.9) with ESMTP id hAT89Cen025645; Sat, 29 Nov 2003 00:09:12 -0800 (PST) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.homeunix.com (8.12.9/8.12.9/Submit) id hAT89CWs025644; Sat, 29 Nov 2003 00:09:12 -0800 (PST) (envelope-from das@FreeBSD.ORG) Date: Sat, 29 Nov 2003 00:09:11 -0800 From: David Schultz To: Steve Kargl Message-ID: <20031129080911.GA25448@VARK.homeunix.com> Mail-Followup-To: Steve Kargl , freebsd-standards@FreeBSD.ORG References: <20031129000133.GA30662@troutmask.apl.washington.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031129000133.GA30662@troutmask.apl.washington.edu> cc: freebsd-standards@FreeBSD.ORG 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 08:11:37 -0000 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.)