diff options
author | das <das@FreeBSD.org> | 2005-04-08 01:24:08 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2005-04-08 01:24:08 +0000 |
commit | 15bd306d7ac7202143a052f70402305a2c04968d (patch) | |
tree | 061e2bb48941ddfb39b8e3fd0b0c7710556777cf /lib | |
parent | 4df744a4717c111c1ef2d75a7215e2a785dfc73c (diff) | |
download | FreeBSD-src-15bd306d7ac7202143a052f70402305a2c04968d.zip FreeBSD-src-15bd306d7ac7202143a052f70402305a2c04968d.tar.gz |
Add roundl(), lroundl(), and llroundl().
Diffstat (limited to 'lib')
-rw-r--r-- | lib/msun/Makefile | 11 | ||||
-rw-r--r-- | lib/msun/man/lround.3 | 28 | ||||
-rw-r--r-- | lib/msun/man/round.3 | 20 | ||||
-rw-r--r-- | lib/msun/src/math.h | 6 | ||||
-rw-r--r-- | lib/msun/src/s_llroundl.c | 11 | ||||
-rw-r--r-- | lib/msun/src/s_lroundl.c | 11 | ||||
-rw-r--r-- | lib/msun/src/s_roundl.c | 51 |
7 files changed, 120 insertions, 18 deletions
diff --git a/lib/msun/Makefile b/lib/msun/Makefile index ca4962b..2775010 100644 --- a/lib/msun/Makefile +++ b/lib/msun/Makefile @@ -47,12 +47,12 @@ COMMON_SRCS= b_exp.c b_log.c b_tgamma.c \ s_fmax.c s_fmaxf.c s_fmaxl.c s_fmin.c \ s_fminf.c s_fminl.c s_frexp.c s_frexpf.c s_ilogb.c s_ilogbf.c \ s_ilogbl.c s_isfinite.c s_isnan.c s_isnormal.c \ - s_llrint.c s_llrintf.c s_llround.c s_llroundf.c \ + s_llrint.c s_llrintf.c s_llround.c s_llroundf.c s_llroundl.c \ s_log1p.c s_log1pf.c s_logb.c s_logbf.c s_lrint.c s_lrintf.c \ - s_lround.c s_lroundf.c s_modff.c \ + s_lround.c s_lroundf.c s_lroundl.c s_modff.c \ s_nearbyint.c s_nextafter.c s_nextafterf.c \ s_nexttowardf.c s_remquo.c s_remquof.c \ - s_rint.c s_rintf.c s_round.c s_roundf.c \ + s_rint.c s_rintf.c s_round.c s_roundf.c s_roundl.c \ s_scalbln.c s_scalbn.c s_scalbnf.c s_signbit.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_trunc.c s_truncf.c \ @@ -137,14 +137,15 @@ MLINKS+=j0.3 j1.3 j0.3 jn.3 j0.3 y0.3 j0.3 y1.3 j0.3 y1f.3 j0.3 yn.3 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+=lrint.3 llrint.3 lrint.3 llrintf.3 lrint.3 lrintf.3 -MLINKS+=lround.3 llround.3 lround.3 llroundf.3 lround.3 lroundf.3 +MLINKS+=lround.3 llround.3 lround.3 llroundf.3 lround.3 llroundl.3 \ + lround.3 lroundf.3 lround.3 lroundl.3 MLINKS+=nextafter.3 nextafterf.3 nextafter.3 nextafterl.3 MLINKS+=nextafter.3 nexttoward.3 nextafter.3 nexttowardf.3 MLINKS+=nextafter.3 nexttowardl.3 MLINKS+=remainder.3 remainderf.3 MLINKS+=remainder.3 remquo.3 remainder.3 remquof.3 MLINKS+=rint.3 rintf.3 rint.3 nearbyint.3 rint.3 nearbyintf.3 -MLINKS+=round.3 roundf.3 +MLINKS+=round.3 roundf.3 round.3 roundl.3 MLINKS+=scalbn.3 scalbln.3 scalbn.3 scalblnf.3 scalbn.3 scalblnl.3 MLINKS+=scalbn.3 scalbnf.3 scalbn.3 scalbnl.3 MLINKS+=sin.3 sinf.3 diff --git a/lib/msun/man/lround.3 b/lib/msun/man/lround.3 index d45bb27..f2c4a3f 100644 --- a/lib/msun/man/lround.3 +++ b/lib/msun/man/lround.3 @@ -24,14 +24,16 @@ .\" .\" $FreeBSD$ .\" -.Dd January 11, 2005 +.Dd April 7, 2005 .Dt LROUND 3 .Os .Sh NAME .Nm llround , .Nm llroundf , +.Nm llroundl , .Nm lround , -.Nm lroundf +.Nm lroundf , +.Nm lroundl .Nd "convert to nearest integral value" .Sh LIBRARY .Lb libm @@ -41,10 +43,14 @@ .Fn llround "double x" .Ft "long long" .Fn llroundf "float x" +.Ft "long long" +.Fn llroundl "long double x" .Ft long .Fn lround "double x" .Ft long .Fn lroundf "float x" +.Ft long +.Fn lroundl "long double x" .Sh DESCRIPTION The .Fn lround @@ -70,8 +76,10 @@ is equivalent to The .Fn llround , .Fn llroundf , -and +.Fn llroundl , .Fn lroundf +and +.Fn lroundl functions differ from .Fn lround only in their input and output types. @@ -84,11 +92,21 @@ only in their input and output types. The .Fn llround , .Fn llroundf , +.Fn llroundl , .Fn lround , +.Fn lroundf , and -.Fn lroundf +.Fn lroundl functions conform to .St -isoC-99 . .Sh HISTORY -These routines first appeared in +The +.Ft float +and +.Ft double +versions of these routines first appeared in .Fx 5.4 . +The +.Ft long double +versions appeared in +.Fx 6.0 . diff --git a/lib/msun/man/round.3 b/lib/msun/man/round.3 index 5f34ce0..262cf0f 100644 --- a/lib/msun/man/round.3 +++ b/lib/msun/man/round.3 @@ -24,12 +24,13 @@ .\" .\" $FreeBSD$ .\" -.Dd November 29, 2003 +.Dd April 7, 2005 .Dt ROUND 3 .Os .Sh NAME .Nm round , -.Nm roundf +.Nm roundf , +.Nm roundl .Nd round to nearest integral value .Sh LIBRARY .Lb libm @@ -39,11 +40,14 @@ .Fn round "double x" .Ft float .Fn roundf "float x" +.Ft long double +.Fn roundl "long double x" .Sh DESCRIPTION The -.Fn round +.Fn round , +.Fn roundf , and -.Fn roundf +.Fn roundl functions return the nearest integral value to .Fa x ; if @@ -61,9 +65,7 @@ absolute value (i.e., they round away from zero). .Xr rint 3 , .Xr trunc 3 .Sh STANDARDS -The -.Fn round -function conforms to +These functions conform to .St -isoC-99 . .Sh HISTORY The @@ -72,3 +74,7 @@ and .Fn roundf functions appeared in .Fx 5.3 . +The +.Fn roundl +function appeared in +.Fx 6.0 . diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h index 27c4a1c..5ac6e56 100644 --- a/lib/msun/src/math.h +++ b/lib/msun/src/math.h @@ -428,14 +428,18 @@ long double ldexpl(long double, int); #if 0 long double lgammal(long double); long long llrintl(long double); +#endif long long llroundl(long double); +#if 0 long double log10l(long double); long double log1pl(long double); long double log2l(long double); long double logbl(long double); long double logl(long double); long lrintl(long double); +#endif long lroundl(long double); +#if 0 long double modfl(long double, long double *); /* fundamentally !__pure2 */ long double nanl(const char *) __pure2; long double nearbyintl(long double); @@ -449,8 +453,8 @@ long double powl(long double, long double); long double remainderl(long double, long double); long double remquol(long double, long double, int *); long double rintl(long double); -long double roundl(long double); #endif +long double roundl(long double); long double scalblnl(long double, long); long double scalbnl(long double, int); #if 0 diff --git a/lib/msun/src/s_llroundl.c b/lib/msun/src/s_llroundl.c new file mode 100644 index 0000000..02c44eb --- /dev/null +++ b/lib/msun/src/s_llroundl.c @@ -0,0 +1,11 @@ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define type long double +#define roundit roundl +#define dtype long long +#define DTYPE_MIN LLONG_MIN +#define DTYPE_MAX LLONG_MAX +#define fn llroundl + +#include "s_lround.c" diff --git a/lib/msun/src/s_lroundl.c b/lib/msun/src/s_lroundl.c new file mode 100644 index 0000000..e410827 --- /dev/null +++ b/lib/msun/src/s_lroundl.c @@ -0,0 +1,11 @@ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define type long double +#define roundit roundl +#define dtype long +#define DTYPE_MIN LONG_MIN +#define DTYPE_MAX LONG_MAX +#define fn lroundl + +#include "s_lround.c" diff --git a/lib/msun/src/s_roundl.c b/lib/msun/src/s_roundl.c new file mode 100644 index 0000000..0cb688b --- /dev/null +++ b/lib/msun/src/s_roundl.c @@ -0,0 +1,51 @@ +/*- + * 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> +__FBSDID("$FreeBSD$"); + +#include <math.h> + +long double +roundl(long double x) +{ + long double t; + + if (!isfinite(x)) + return (x); + + if (x >= 0.0) { + t = ceill(x); + if (t - x > 0.5) + t -= 1.0; + return (t); + } else { + t = ceill(-x); + if (t + x > 0.5) + t -= 1.0; + return (-t); + } +} |