Module Name:    src
Committed By:   abs
Date:           Thu Dec  9 22:52:59 UTC 2010

Modified Files:
        src/lib/libm: Makefile
        src/lib/libm/noieee_src: n_floor.c
Added Files:
        src/lib/libm/noieee_src: n_lround.c n_lroundf.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/lib/libm/Makefile
cvs rdiff -u -r1.6 -r1.7 src/lib/libm/noieee_src/n_floor.c
cvs rdiff -u -r0 -r1.1 src/lib/libm/noieee_src/n_lround.c \
    src/lib/libm/noieee_src/n_lroundf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libm/Makefile
diff -u src/lib/libm/Makefile:1.98 src/lib/libm/Makefile:1.99
--- src/lib/libm/Makefile:1.98	Wed Sep 15 16:11:29 2010
+++ src/lib/libm/Makefile	Thu Dec  9 22:52:59 2010
@@ -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
 
 

Index: src/lib/libm/noieee_src/n_floor.c
diff -u src/lib/libm/noieee_src/n_floor.c:1.6 src/lib/libm/noieee_src/n_floor.c:1.7
--- src/lib/libm/noieee_src/n_floor.c:1.6	Thu May 13 20:35:40 2004
+++ src/lib/libm/noieee_src/n_floor.c	Thu Dec  9 22:52:59 2010
@@ -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);
+}

Added files:

Index: src/lib/libm/noieee_src/n_lround.c
diff -u /dev/null src/lib/libm/noieee_src/n_lround.c:1.1
--- /dev/null	Thu Dec  9 22:52:59 2010
+++ src/lib/libm/noieee_src/n_lround.c	Thu Dec  9 22:52:59 2010
@@ -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);
+	}
+}
Index: src/lib/libm/noieee_src/n_lroundf.c
diff -u /dev/null src/lib/libm/noieee_src/n_lroundf.c:1.1
--- /dev/null	Thu Dec  9 22:52:59 2010
+++ src/lib/libm/noieee_src/n_lroundf.c	Thu Dec  9 22:52:59 2010
@@ -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);
+	}
+}

Reply via email to