From owner-freebsd-standards@FreeBSD.ORG Wed Dec 10 09:11:53 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 BB83B16A4CE; Wed, 10 Dec 2003 09:11:53 -0800 (PST) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.208.78.105]) by mx1.FreeBSD.org (Postfix) with ESMTP id 30CC543D1D; Wed, 10 Dec 2003 09:11:51 -0800 (PST) (envelope-from kargl@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) hBAHBowg007530; Wed, 10 Dec 2003 09:11:50 -0800 (PST) (envelope-from kargl@troutmask.apl.washington.edu) Received: (from kargl@localhost)hBAHBoEL007529; Wed, 10 Dec 2003 09:11:50 -0800 (PST) (envelope-from kargl) From: "Steven G. Kargl" Message-Id: <200312101711.hBAHBoEL007529@troutmask.apl.washington.edu> In-Reply-To: <200311291810.hATIAIWu084953@freefall.freebsd.org> To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-standards@FreeBSD.org Date: Wed, 10 Dec 2003 09:11:50 -0800 (PST) X-Mailer: ELM [version 2.4ME+ PL99f (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM1071076310-7460-0_ Content-Transfer-Encoding: 7bit Subject: Re: standards/59797: Implement C99's round[f]() math fucntions 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: Wed, 10 Dec 2003 17:11:53 -0000 --ELM1071076310-7460-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII FreeBSD-gnats-submit@FreeBSD.org wrote: > Thank you very much for your problem report. > It has the internal identification `standards/59797'. > The individual assigned to look at your > report is: freebsd-standards. > > You can access the state of your problem report at any time > via this link: > > http://www.freebsd.org/cgi/query-pr.cgi?pr=59797 > > >Category: standards > >Responsible: freebsd-standards > >Synopsis: Implement C99's round[f]() math fucntions > >Arrival-Date: Sat Nov 29 10:10:18 PST 2003 > Aargh. Here the actual patch that 1) handle Inf and NaN on input. 2) add a BUGS section to the man page about FP exception handling 3) hopefully comply better with style(9) -- Steve http://troutmask.apl.washington.edu/~kargl/ --ELM1071076310-7460-0_ Content-Transfer-Encoding: 7bit Content-Type: text/x-patch Content-Disposition: attachment; filename=msun.patch Content-Description: diff -Nbur msun.orig/Makefile msun/Makefile --- msun.orig/Makefile Sat Oct 25 02:32:18 2003 +++ msun/Makefile Tue Dec 9 20:39:18 2003 @@ -84,7 +84,8 @@ s_floor.c s_floorf.c s_frexp.c s_frexpf.c s_ilogb.c s_ilogbf.c \ s_isnanf.c s_ldexpf.c s_lib_version.c s_log1p.c \ s_log1pf.c s_logb.c s_logbf.c s_matherr.c s_modff.c \ - s_nextafter.c s_nextafterf.c s_rint.c s_rintf.c s_scalbn.c s_scalbnf.c \ + s_nextafter.c s_nextafterf.c s_rint.c s_rintf.c s_round.c s_roundf.c \ + s_scalbn.c s_scalbnf.c \ s_signgam.c s_significand.c s_significandf.c s_sin.c s_sinf.c s_tan.c \ s_tanf.c s_tanh.c s_tanhf.c \ w_acos.c w_acosf.c w_acosh.c w_acoshf.c w_asin.c w_asinf.c w_atan2.c \ @@ -121,7 +122,7 @@ MAN= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 ceil.3 \ cos.3 cosh.3 erf.3 exp.3 fabs.3 floor.3 fmod.3 hypot.3 ieee.3 \ - ieee_test.3 j0.3 lgamma.3 math.3 rint.3 sin.3 sinh.3 sqrt.3 \ + ieee_test.3 j0.3 lgamma.3 math.3 rint.3 round.3 sin.3 sinh.3 sqrt.3 \ tan.3 tanh.3 MLINKS+=acos.3 acosf.3 @@ -153,6 +154,7 @@ MLINKS+=j0.3 j0f.3 j0.3 j1f.3 j0.3 jnf.3 j0.3 y0f.3 j0.3 ynf.3 MLINKS+=lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 lgammaf.3 lgamma.3 tgamma.3 MLINKS+=rint.3 rintf.3 +MLINKS+=round.3 roundf.3 MLINKS+=sin.3 sinf.3 MLINKS+=sinh.3 sinhf.3 MLINKS+=sqrt.3 cbrt.3 sqrt.3 cbrtf.3 sqrt.3 sqrtf.3 diff -Nbur msun.orig/man/round.3 msun/man/round.3 --- msun.orig/man/round.3 Wed Dec 31 16:00:00 1969 +++ msun/man/round.3 Tue Dec 9 20:35:48 2003 @@ -0,0 +1,71 @@ +.\" Copyright (c) 2003, Steven G. Kargl +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd November 29, 2003 +.Dt ROUND 3 +.Os +.Sh NAME +.Nm round , +.Nm roundf +.Nd nearest integral value; if the argument is halfway between two integral +values then round away from zero +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn round "double x" +.Ft float +.Fn roundf "float x" +.Sh DESCRIPTION +The +.Fn round +and the +.Fn roundf +functions return the nearest integral value to +.Fa x ; +if +.Fa x +lies halfway between two integral values, then these +functions return the integral value with the larger +absolute value (i.e., they round away from zero). +.Sh SEE ALSO +.Xr ceil 3 , +.Xr floor 3 , +.Xr ieee 3 , +.Xr math 3 , +.Xr rint 3 +.Sh BUGS +.Fn round +and +.Fn roundf +do currently support floating-point exception handling as +specified by +.St -isoC-99 . +.Sh STANDARDS +The +.Fn round +function conforms to +.St -isoC-99 . + diff -Nbur msun.orig/src/math.h msun/src/math.h --- msun.orig/src/math.h Thu Oct 23 01:23:38 2003 +++ msun/src/math.h Tue Dec 9 20:29:39 2003 @@ -191,6 +191,7 @@ double fabs(double); double floor(double); double fmod(double, double); +double round(double); /* * These functions are not in C90 so they can be "right". The ones that @@ -281,6 +282,7 @@ float fabsf(float); float floorf(float); float fmodf(float, float); +float roundf(float); float erff(float); float erfcf(float) __pure2; diff -Nbur msun.orig/src/s_round.c msun/src/s_round.c --- msun.orig/src/s_round.c Wed Dec 31 16:00:00 1969 +++ msun/src/s_round.c Tue Dec 9 20:33:41 2003 @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2003, Steven G. Kargl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + + +#include + +double +round(double x) +{ + double t; + int i; + + if ((i = fpclassify(x)) == FP_INFINITE || i == FP_NAN) + return (x); + + if (x >= 0.0) { + t = ceil(x); + if (t - x > 0.5) t -= 1.0; + return (t); + } else { + t = ceil(-x); + if (t + x > 0.5) t -= 1.0; + return (-t); + } +} diff -Nbur msun.orig/src/s_roundf.c msun/src/s_roundf.c --- msun.orig/src/s_roundf.c Wed Dec 31 16:00:00 1969 +++ msun/src/s_roundf.c Tue Dec 9 20:32:58 2003 @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2003, Steven G. Kargl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +float +roundf(float x) +{ + float t; + int i; + + if ((i = fpclassify(x)) == FP_INFINITE || i == FP_NAN) + return (x); + + 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; + } +} --ELM1071076310-7460-0_--