diff options
| author | abs <abs@NetBSD.org> | 2010-12-09 22:52:59 +0000 |
|---|---|---|
| committer | abs <abs@NetBSD.org> | 2010-12-09 22:52:59 +0000 |
| commit | 2ea4fe3d41103408178feb31f8bcd1ed36ce9525 (patch) | |
| tree | c79b0d0de0e3dc893d0638c0945e8e5e83f7a694 /lib/libm | |
| parent | 68f18d6497b1cb1f5d214a378a69391962b3203e (diff) | |
Add noieee versions for lround(), lroundf(), lrint(), lrintf(),
llrint() and llrintf(). Code copied from round(), roundf() and
rint() and modified for return values. Its possible this may not
do the right things in edge cases, but if so its likely to have
the same issues as the existing round(), roundf() and rint().
All this used by vax (only), and should allow xnest to complete
build.
Diffstat (limited to 'lib/libm')
| -rw-r--r-- | lib/libm/Makefile | 4 | ||||
| -rw-r--r-- | lib/libm/noieee_src/n_floor.c | 74 | ||||
| -rw-r--r-- | lib/libm/noieee_src/n_lround.c | 53 | ||||
| -rw-r--r-- | lib/libm/noieee_src/n_lroundf.c | 53 |
4 files changed, 181 insertions, 3 deletions
diff --git a/lib/libm/Makefile b/lib/libm/Makefile index 2b46a46c45b..c4b881d43b9 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.98 2010/09/15 16:11:29 christos Exp $ +# $NetBSD: Makefile,v 1.99 2010/12/09 22:52:59 abs Exp $ # # @(#)Makefile 5.1beta 93/09/24 # @@ -163,7 +163,7 @@ NOIEEE_SRCS = n_asincos.c n_acosh.c n_asinh.c n_atan.c n_atanh.c n_cosh.c \ n_lgamma.c n_j0.c n_j1.c n_jn.c n_log.c n_log10.c n_log1p.c \ n_log__L.c n_pow.c n_sinh.c n_tanh.c \ n_sincos.c n_tan.c \ - n_round.c n_roundf.c + n_round.c n_roundf.c n_lround.c n_lroundf.c # n_sqrt.c n_argred.c n_infnan.c n_atan2.c n_cabs.c n_cbrt.c n_support.c diff --git a/lib/libm/noieee_src/n_floor.c b/lib/libm/noieee_src/n_floor.c index baa65e6e156..2299aeb982a 100644 --- a/lib/libm/noieee_src/n_floor.c +++ b/lib/libm/noieee_src/n_floor.c @@ -1,4 +1,4 @@ -/* $NetBSD: n_floor.c,v 1.6 2004/05/13 20:35:40 mhitch Exp $ */ +/* $NetBSD: n_floor.c,v 1.7 2010/12/09 22:52:59 abs Exp $ */ /* * Copyright (c) 1985, 1993 * The Regents of the University of California. All rights reserved. @@ -144,3 +144,75 @@ rint(double x) return (t - s); } #endif /* not national */ + +long +lrint(double x) +{ + double s; + volatile double t; + const double one = 1.0; + +#if !defined(__vax__)&&!defined(tahoe) + if (x != x) /* NaN */ + return (x); +#endif /* !defined(__vax__)&&!defined(tahoe) */ + if (copysign(x,one) >= L) /* already an integer */ + return (x); + s = copysign(L,x); + t = x + s; /* x+s rounded to integer */ + return (t - s); +} + +long long +llrint(double x) +{ + double s; + volatile double t; + const double one = 1.0; + +#if !defined(__vax__)&&!defined(tahoe) + if (x != x) /* NaN */ + return (x); +#endif /* !defined(__vax__)&&!defined(tahoe) */ + if (copysign(x,one) >= L) /* already an integer */ + return (x); + s = copysign(L,x); + t = x + s; /* x+s rounded to integer */ + return (t - s); +} + +long +lrintf(float x) +{ + float s; + volatile float t; + const float one = 1.0; + +#if !defined(__vax__)&&!defined(tahoe) + if (x != x) /* NaN */ + return (x); +#endif /* !defined(__vax__)&&!defined(tahoe) */ + if (copysign(x,one) >= L) /* already an integer */ + return (x); + s = copysign(L,x); + t = x + s; /* x+s rounded to integer */ + return (t - s); +} + +long long +llrintf(float x) +{ + float s; + volatile float t; + const float one = 1.0; + +#if !defined(__vax__)&&!defined(tahoe) + if (x != x) /* NaN */ + return (x); +#endif /* !defined(__vax__)&&!defined(tahoe) */ + if (copysign(x,one) >= L) /* already an integer */ + return (x); + s = copysign(L,x); + t = x + s; /* x+s rounded to integer */ + return (t - s); +} diff --git a/lib/libm/noieee_src/n_lround.c b/lib/libm/noieee_src/n_lround.c new file mode 100644 index 00000000000..bc35c891a80 --- /dev/null +++ b/lib/libm/noieee_src/n_lround.c @@ -0,0 +1,53 @@ +/*- + * 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: n_lround.c,v 1.1 2010/12/09 22:52:59 abs 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> + +long +lround(double x) +{ + long t; + + 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 --git a/lib/libm/noieee_src/n_lroundf.c b/lib/libm/noieee_src/n_lroundf.c new file mode 100644 index 00000000000..4bf4ec1e570 --- /dev/null +++ b/lib/libm/noieee_src/n_lroundf.c @@ -0,0 +1,53 @@ +/*- + * 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: n_lroundf.c,v 1.1 2010/12/09 22:52:59 abs 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> + +long +lroundf(float x) +{ + long 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); + } +} |
