Date: Sat, 29 Nov 2003 00:09:11 -0800 From: David Schultz <das@FreeBSD.ORG> To: Steve Kargl <sgk@troutmask.apl.washington.edu> Cc: freebsd-standards@FreeBSD.ORG Subject: Re: Implementing C99's roundf(), round(), and roundl() Message-ID: <20031129080911.GA25448@VARK.homeunix.com> In-Reply-To: <20031129000133.GA30662@troutmask.apl.washington.edu> References: <20031129000133.GA30662@troutmask.apl.washington.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <math.h> > > 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.)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031129080911.GA25448>