From owner-freebsd-standards@FreeBSD.ORG Mon Jan 19 14:13:19 2004 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 96F8416A4CF for ; Mon, 19 Jan 2004 14:13:19 -0800 (PST) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.208.78.105]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4D6B043D4C for ; Mon, 19 Jan 2004 14:13:15 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) i0JMDETA065925; Mon, 19 Jan 2004 14:13:14 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost)i0JMDEEL065924; Mon, 19 Jan 2004 14:13:14 -0800 (PST) (envelope-from sgk) Date: Mon, 19 Jan 2004 14:13:14 -0800 From: Steve Kargl To: Bruce Evans , freebsd-standards@FreeBSD.ORG Message-ID: <20040119221314.GA65652@troutmask.apl.washington.edu> References: <20031129000133.GA30662@troutmask.apl.washington.edu> <20031129080911.GA25448@VARK.homeunix.com> <20031129163105.GA32651@troutmask.apl.washington.edu> <20031130213951.GA37082@VARK.homeunix.com> <20031201182219.O4431@gamplex.bde.org> <20031201203512.GA95524@troutmask.apl.washington.edu> <20031202091936.I8778@gamplex.bde.org> <20040119213142.GA72803@VARK.homeunix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040119213142.GA72803@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: Mon, 19 Jan 2004 22:13:19 -0000 On Mon, Jan 19, 2004 at 01:31:42PM -0800, David Schultz wrote: > > double > round(double x) > { > double result; > fp_except_t fe; > > fe = fpresetsticky(0); > result = rint(x); > if (fpgetsticky() & FP_X_IMP) { > result = copysign(floor(fabs(x) + 0.5), x); > fe |= FP_X_IMP; > } > fpresetsticky(fe); > return (result); > } > > Does this seem reasonable? Don't you need rnd = fpsetround(FP_RN); /* Set to known rounding mode */ result = rint(x); fpsetround(rnd); /* Reset to whatever the user had */ to ensure that rint() rounds to an expected value. int main(void) { double u, v, x; x = 0.5; fpsetround(FP_RM); u = round(x); fpsetround(FP_RP); v = round(x); /* Does u equal v ? */ } BTW, thanks for working on this issue. -- Steve