Date: Mon, 19 Jan 2004 14:13:14 -0800 From: Steve Kargl <sgk@troutmask.apl.washington.edu> To: Bruce Evans <bde@zeta.org.au>, freebsd-standards@FreeBSD.ORG Subject: Re: Implementing C99's roundf(), round(), and roundl() Message-ID: <20040119221314.GA65652@troutmask.apl.washington.edu> In-Reply-To: <20040119213142.GA72803@VARK.homeunix.com> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040119221314.GA65652>