Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libm Add noieee versions for lround(), lroundf(), lrint(...
details: https://anonhg.NetBSD.org/src/rev/3d0337a2568b
branches: trunk
changeset: 759446:3d0337a2568b
user: abs <abs%NetBSD.org@localhost>
date: Thu Dec 09 22:52:59 2010 +0000
description:
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:
lib/libm/Makefile | 4 +-
lib/libm/noieee_src/n_floor.c | 74 ++++++++++++++++++++++++++++++++++++++++-
lib/libm/noieee_src/n_lround.c | 53 +++++++++++++++++++++++++++++
lib/libm/noieee_src/n_lroundf.c | 53 +++++++++++++++++++++++++++++
4 files changed, 181 insertions(+), 3 deletions(-)
diffs (217 lines):
diff -r c79851f6172c -r 3d0337a2568b lib/libm/Makefile
--- a/lib/libm/Makefile Thu Dec 09 22:34:37 2010 +0000
+++ b/lib/libm/Makefile Thu Dec 09 22:52:59 2010 +0000
@@ -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 @@
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 -r c79851f6172c -r 3d0337a2568b lib/libm/noieee_src/n_floor.c
--- a/lib/libm/noieee_src/n_floor.c Thu Dec 09 22:34:37 2010 +0000
+++ b/lib/libm/noieee_src/n_floor.c Thu Dec 09 22:52:59 2010 +0000
@@ -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 @@
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 -r c79851f6172c -r 3d0337a2568b lib/libm/noieee_src/n_lround.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/noieee_src/n_lround.c Thu Dec 09 22:52:59 2010 +0000
@@ -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 -r c79851f6172c -r 3d0337a2568b lib/libm/noieee_src/n_lroundf.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/noieee_src/n_lroundf.c Thu Dec 09 22:52:59 2010 +0000
@@ -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);
+ }
+}
Home |
Main Index |
Thread Index |
Old Index