lib/24252: Add C99 functions round(3) and roundf(3).
libm minor unchanged; ride a recent bump. From FreeBSD.
This commit is contained in:
parent
b65388fd20
commit
bc836a3102
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.712 2004/07/05 11:08:37 sketch Exp $
|
||||
# $NetBSD: mi,v 1.713 2004/07/10 13:49:09 junyoung Exp $
|
||||
./etc/mtree/set.comp comp-sys-root
|
||||
./usr/bin/addr2line comp-debug-bin bfd
|
||||
./usr/bin/ar comp-util-bin bfd
|
||||
@ -4008,6 +4008,8 @@
|
||||
./usr/share/man/cat3/ripemd.0 comp-obsolete obsolete
|
||||
./usr/share/man/cat3/rmd160.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/rmtops.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/round.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/roundf.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/rpc.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/rpc_broadcast.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/rpc_broadcast_exp.0 comp-c-catman .cat
|
||||
@ -7738,6 +7740,8 @@
|
||||
./usr/share/man/man3/ripemd.3 comp-obsolete obsolete
|
||||
./usr/share/man/man3/rmd160.3 comp-c-man .man
|
||||
./usr/share/man/man3/rmtops.3 comp-c-man .man
|
||||
./usr/share/man/man3/round.3 comp-c-man .man
|
||||
./usr/share/man/man3/roundf.3 comp-c-man .man
|
||||
./usr/share/man/man3/rpc.3 comp-c-man .man
|
||||
./usr/share/man/man3/rpc_broadcast.3 comp-c-man .man
|
||||
./usr/share/man/man3/rpc_broadcast_exp.3 comp-c-man .man
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: math.h,v 1.37 2004/07/01 16:09:21 drochner Exp $ */
|
||||
/* $NetBSD: math.h,v 1.38 2004/07/10 13:49:09 junyoung Exp $ */
|
||||
|
||||
/*
|
||||
* ====================================================
|
||||
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
@ -129,15 +129,15 @@ extern int signgam;
|
||||
enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
|
||||
|
||||
#define _LIB_VERSION_TYPE enum fdversion
|
||||
#define _LIB_VERSION _fdlib_version
|
||||
#define _LIB_VERSION _fdlib_version
|
||||
|
||||
/* if global variable _LIB_VERSION is not desirable, one may
|
||||
* change the following to be a constant by:
|
||||
/* if global variable _LIB_VERSION is not desirable, one may
|
||||
* change the following to be a constant by:
|
||||
* #define _LIB_VERSION_TYPE const enum version
|
||||
* In that case, after one initializes the value _LIB_VERSION (see
|
||||
* s_lib_version.c) during compile time, it cannot be modified
|
||||
* in the middle of a program
|
||||
*/
|
||||
*/
|
||||
extern _LIB_VERSION_TYPE _LIB_VERSION;
|
||||
|
||||
#define _IEEE_ fdlibm_ieee
|
||||
@ -157,12 +157,12 @@ struct exception {
|
||||
|
||||
#define HUGE MAXFLOAT
|
||||
|
||||
/*
|
||||
/*
|
||||
* set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
|
||||
* (one may replace the following line by "#include <values.h>")
|
||||
*/
|
||||
|
||||
#define X_TLOSS 1.41484755040568800000e+16
|
||||
#define X_TLOSS 1.41484755040568800000e+16
|
||||
|
||||
#define DOMAIN 1
|
||||
#define SING 2
|
||||
@ -203,6 +203,7 @@ double ceil __P((double));
|
||||
double fabs __P((double));
|
||||
double floor __P((double));
|
||||
double fmod __P((double, double));
|
||||
double round __P((double));
|
||||
|
||||
#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
|
||||
double erf __P((double));
|
||||
@ -307,6 +308,7 @@ float lgammaf __P((float));
|
||||
float ceilf __P((float));
|
||||
float floorf __P((float));
|
||||
float rintf __P((float));
|
||||
float roundf __P((float));
|
||||
long int lrint __P((double));
|
||||
long int lrintf __P((float));
|
||||
/* LONGLONG */
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.63 2004/07/01 19:08:21 drochner Exp $
|
||||
# $NetBSD: Makefile,v 1.64 2004/07/10 13:49:09 junyoung Exp $
|
||||
#
|
||||
# @(#)Makefile 5.1beta 93/09/24
|
||||
#
|
||||
@ -121,9 +121,9 @@ COMMON_SRCS = e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \
|
||||
s_floor.c s_floorf.c s_frexpf.c s_ilogb.c s_ilogbf.c \
|
||||
s_isinff.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_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 \
|
||||
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 \
|
||||
w_atan2f.c w_atanh.c w_atanhf.c w_cabs.c w_cabsf.c w_cosh.c w_coshf.c \
|
||||
w_drem.c w_dremf.c w_exp.c w_expf.c w_fmod.c w_fmodf.c w_gamma.c \
|
||||
@ -170,8 +170,8 @@ SRCS:=${SRCS} n_sqrt.S n_argred.S n_infnan.S n_atan2.S n_cabs.S n_cbrt.S \
|
||||
|
||||
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 isinff.3 j0.3 lgamma.3 math.3 rint.3 sin.3 sinh.3 sqrt.3 \
|
||||
tan.3 tanh.3
|
||||
ieee_test.3 isinff.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
|
||||
MLINKS+=acosh.3 acoshf.3
|
||||
@ -209,6 +209,7 @@ MLINKS+=sinf.3 sinhf.3
|
||||
MLINKS+=sqrt.3 sqrtf.3 sqrt.3 cbrt.3 sqrt.3 cbrtf.3
|
||||
MLINKS+=tan.3 tanf.3
|
||||
MLINKS+=tanh.3 tanhf.3
|
||||
MLINKS+=round.3 roundf.3
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
.include <bsd.subdir.mk>
|
||||
|
66
lib/libm/man/round.3
Normal file
66
lib/libm/man/round.3
Normal file
@ -0,0 +1,66 @@
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" $NetBSD: round.3,v 1.1 2004/07/10 13:49:10 junyoung Exp $
|
||||
.\" $FreeBSD: src/lib/msun/man/round.3,v 1.2 2004/06/20 09:27:17 das Exp $
|
||||
.\"
|
||||
.Dd July 9, 2004
|
||||
.Dt ROUND 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm round ,
|
||||
.Nm roundf
|
||||
.Nd round to nearest integral value
|
||||
.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
|
||||
.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 ,
|
||||
.Xr trunc 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn round
|
||||
function conforms to
|
||||
.St -isoC-99 .
|
58
lib/libm/src/s_round.c
Normal file
58
lib/libm/src/s_round.c
Normal file
@ -0,0 +1,58 @@
|
||||
/*-
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: s_round.c,v 1.1 2004/07/10 13:49:10 junyoung Exp $");
|
||||
#if 0
|
||||
__FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.1 2004/06/07 08:05:36 das Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
double
|
||||
round(double x)
|
||||
{
|
||||
double t;
|
||||
int i;
|
||||
|
||||
i = fpclassify(x);
|
||||
if (i == 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);
|
||||
}
|
||||
}
|
58
lib/libm/src/s_roundf.c
Normal file
58
lib/libm/src/s_roundf.c
Normal file
@ -0,0 +1,58 @@
|
||||
/*-
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBM_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: s_roundf.c,v 1.1 2004/07/10 13:49:10 junyoung Exp $");
|
||||
#if 0
|
||||
__FBSDID("$FreeBSD: src/lib/msun/src/s_roundf.c,v 1.1 2004/06/07 08:05:36 das Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
float
|
||||
roundf(float x)
|
||||
{
|
||||
float t;
|
||||
int i;
|
||||
|
||||
i = fpclassify(x);
|
||||
if (i == 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user