Module Name:    src
Committed By:   christos
Date:           Sat May  6 18:03:25 UTC 2017

Modified Files:
        src/lib/libm: Makefile
Added Files:
        src/lib/libm/src: s_llrint.c s_llrintf.c s_llrintl.c s_llround.c
            s_llroundf.c s_llroundl.c s_lrint.c s_lrintf.c s_lrintl.c
            s_lround.c s_lroundf.c s_lroundl.c
Removed Files:
        src/lib/libm/src: llrint.c llrintf.c llround.c llroundf.c lrint.c
            lrintf.c lround.c lroundf.c

Log Message:
Replace our rounding functions with the ones from FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 src/lib/libm/Makefile
cvs rdiff -u -r1.2 -r0 src/lib/libm/src/llrint.c src/lib/libm/src/llrintf.c \
    src/lib/libm/src/llround.c src/lib/libm/src/llroundf.c
cvs rdiff -u -r1.6 -r0 src/lib/libm/src/lrint.c src/lib/libm/src/lrintf.c
cvs rdiff -u -r1.3 -r0 src/lib/libm/src/lround.c src/lib/libm/src/lroundf.c
cvs rdiff -u -r0 -r1.1 src/lib/libm/src/s_llrint.c \
    src/lib/libm/src/s_llrintf.c src/lib/libm/src/s_llrintl.c \
    src/lib/libm/src/s_llround.c src/lib/libm/src/s_llroundf.c \
    src/lib/libm/src/s_llroundl.c src/lib/libm/src/s_lrint.c \
    src/lib/libm/src/s_lrintf.c src/lib/libm/src/s_lrintl.c \
    src/lib/libm/src/s_lround.c src/lib/libm/src/s_lroundf.c \
    src/lib/libm/src/s_lroundl.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.190 src/lib/libm/Makefile:1.191
--- src/lib/libm/Makefile:1.190	Thu Mar 23 14:26:03 2017
+++ src/lib/libm/Makefile	Sat May  6 14:03:24 2017
@@ -1,4 +1,4 @@
-#  $NetBSD: Makefile,v 1.190 2017/03/23 18:26:03 chs Exp $
+#  $NetBSD: Makefile,v 1.191 2017/05/06 18:03:24 christos Exp $
 #
 #  @(#)Makefile 5.1beta 93/09/24
 #
@@ -248,6 +248,10 @@ COMMON_SRCS+= b_exp.c b_log.c b_tgamma.c
 	s_floor.c s_floorf.c s_floorl.c s_frexpf.c \
 	s_ilogb.c s_ilogbf.c s_ilogbl.c \
 	s_isinff.c s_isnanf.c s_lib_version.c s_log1p.c \
+	s_llrint.c s_llrintf.c s_llrintl.c \
+	s_llround.c s_llroundf.c s_llroundl.c \
+	s_lrint.c s_lrintf.c s_lrintl.c \
+	s_lround.c s_lroundf.c s_lroundl.c \
 	s_log1pf.c s_logb.c s_logbf.c s_logbl.c \
 	s_matherr.c s_modff.c s_modfl.c s_nextafter.c s_nextafterl.c \
 	s_nextafterf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c \
@@ -265,8 +269,7 @@ COMMON_SRCS+= b_exp.c b_log.c b_tgamma.c
 	w_log2f.c w_logf.c \
 	w_pow.c w_powf.c w_remainder.c w_remainderf.c w_scalb.c w_scalbf.c \
 	w_sinh.c w_sinhf.c w_sqrt.c w_sqrtf.c w_sqrtl.c \
-	lrint.c lrintf.c llrint.c llrintf.c lround.c lroundf.c llround.c \
-	llroundf.c s_frexp.c s_frexpl.c s_modf.c \
+	s_frexp.c s_frexpl.c s_modf.c \
 	s_fmax.c s_fmaxf.c s_fmaxl.c \
 	s_fmin.c s_fminf.c s_fminl.c s_fdim.c
 

Added files:

Index: src/lib/libm/src/s_llrint.c
diff -u /dev/null src/lib/libm/src/s_llrint.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_llrint.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,13 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_llrint.c 140088 2005-01-11 23:12:55Z das $");
+#else
+__RCSID("$NetBSD: s_llrint.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		double
+#define	roundit		rint
+#define dtype		long long
+#define	fn		llrint
+
+#include "s_lrint.c"
Index: src/lib/libm/src/s_llrintf.c
diff -u /dev/null src/lib/libm/src/s_llrintf.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_llrintf.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,13 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_llrintf.c 140088 2005-01-11 23:12:55Z das $");
+#else
+__RCSID("$NetBSD: s_llrintf.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		float
+#define	roundit		rintf
+#define dtype		long long
+#define	fn		llrintf
+
+#include "s_lrint.c"
Index: src/lib/libm/src/s_llrintl.c
diff -u /dev/null src/lib/libm/src/s_llrintl.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_llrintl.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,13 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_llrintl.c 175309 2008-01-14 02:12:07Z das $");
+#else
+__RCSID("$NetBSD: s_llrintl.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		long double
+#define	roundit		rintl
+#define dtype		long long
+#define	fn		llrintl
+
+#include "s_lrint.c"
Index: src/lib/libm/src/s_llround.c
diff -u /dev/null src/lib/libm/src/s_llround.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_llround.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,15 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_llround.c 144771 2005-04-08 00:52:27Z das $");
+#else
+__RCSID("$NetBSD: s_llround.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		double
+#define	roundit		round
+#define dtype		long long
+#define	DTYPE_MIN	LLONG_MIN
+#define	DTYPE_MAX	LLONG_MAX
+#define	fn		llround
+
+#include "s_lround.c"
Index: src/lib/libm/src/s_llroundf.c
diff -u /dev/null src/lib/libm/src/s_llroundf.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_llroundf.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,15 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_llroundf.c 144771 2005-04-08 00:52:27Z das $");
+#else
+__RCSID("$NetBSD: s_llroundf.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		float
+#define	roundit		roundf
+#define dtype		long long
+#define	DTYPE_MIN	LLONG_MIN
+#define	DTYPE_MAX	LLONG_MAX
+#define	fn		llroundf
+
+#include "s_lround.c"
Index: src/lib/libm/src/s_llroundl.c
diff -u /dev/null src/lib/libm/src/s_llroundl.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_llroundl.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,15 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_llroundl.c 144772 2005-04-08 01:24:08Z das $");
+#else
+__RCSID("$NetBSD: s_llroundl.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		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"
Index: src/lib/libm/src/s_lrint.c
diff -u /dev/null src/lib/libm/src/s_lrint.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_lrint.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,64 @@
+/*-
+ * Copyright (c) 2005 David Schultz <d...@freebsd.org>
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
+
+#include "namespace.h"
+
+#include <sys/cdefs.h>
+#include <fenv.h>
+#include <math.h>
+
+#ifndef stype
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_lrint.c 140088 2005-01-11 23:12:55Z das $");
+#else
+__RCSID("$NetBSD: s_lrint.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+#define stype		double
+#define	roundit		rint
+#define dtype		long
+#define	fn		lrint
+#endif
+
+/*
+ * C99 says we should not raise a spurious inexact exception when an
+ * invalid exception is raised.  Unfortunately, the set of inputs
+ * that overflows depends on the rounding mode when 'dtype' has more
+ * significant bits than 'stype'.  Hence, we bend over backwards for the
+ * sake of correctness; an MD implementation could be more efficient.
+ */
+dtype
+fn(stype x)
+{
+	fenv_t env;
+	dtype d;
+
+	feholdexcept(&env);
+	d = (dtype)roundit(x);
+	if (fetestexcept(FE_INVALID))
+		feclearexcept(FE_INEXACT);
+	feupdateenv(&env);
+	return (d);
+}
Index: src/lib/libm/src/s_lrintf.c
diff -u /dev/null src/lib/libm/src/s_lrintf.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_lrintf.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,13 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_lrintf.c 140088 2005-01-11 23:12:55Z das $");
+#else
+__RCSID("$NetBSD: s_lrintf.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		float
+#define	roundit		rintf
+#define dtype		long
+#define	fn		lrintf
+
+#include "s_lrint.c"
Index: src/lib/libm/src/s_lrintl.c
diff -u /dev/null src/lib/libm/src/s_lrintl.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_lrintl.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,13 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_lrintl.c 175309 2008-01-14 02:12:07Z das $");
+#else
+__RCSID("$NetBSD: s_lrintl.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		long double
+#define	roundit		rintl
+#define dtype		long
+#define	fn		lrintl
+
+#include "s_lrint.c"
Index: src/lib/libm/src/s_lround.c
diff -u /dev/null src/lib/libm/src/s_lround.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_lround.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,72 @@
+/*-
+ * Copyright (c) 2005 David Schultz <d...@freebsd.org>
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
+
+#include "namespace.h"
+
+#include <sys/cdefs.h>
+#include <limits.h>
+#include <fenv.h>
+#include <math.h>
+
+#ifndef stype
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_lround.c 144770 2005-04-08 00:52:16Z das $");
+#else
+__RCSID("$NetBSD: s_lround.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+#define stype		double
+#define	roundit		round
+#define dtype		long
+#define	DTYPE_MIN	LONG_MIN
+#define	DTYPE_MAX	LONG_MAX
+#define	fn		lround
+#endif
+
+/*
+ * If stype has more precision than dtype, the endpoints dtype_(min|max) are
+ * of the form xxx.5; they are "out of range" because lround() rounds away
+ * from 0.  On the other hand, if stype has less precision than dtype, then
+ * all values that are out of range are integral, so we might as well assume
+ * that everything is in range.  At compile time, INRANGE(x) should reduce to
+ * two floating-point comparisons in the former case, or TRUE otherwise.
+ */
+static const stype dtype_min = DTYPE_MIN - 0.5;
+static const stype dtype_max = DTYPE_MAX + 0.5;
+#define	INRANGE(x)	(dtype_max - DTYPE_MAX != 0.5 || \
+			 ((x) > dtype_min && (x) < dtype_max))
+
+dtype
+fn(stype x)
+{
+
+	if (INRANGE(x)) {
+		x = roundit(x);
+		return ((dtype)x);
+	} else {
+		feraiseexcept(FE_INVALID);
+		return (DTYPE_MAX);
+	}
+}
Index: src/lib/libm/src/s_lroundf.c
diff -u /dev/null src/lib/libm/src/s_lroundf.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_lroundf.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,15 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_lroundf.c 144771 2005-04-08 00:52:27Z das $");
+#else
+__RCSID("$NetBSD: s_lroundf.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		float
+#define	roundit		roundf
+#define dtype		long
+#define	DTYPE_MIN	LONG_MIN
+#define	DTYPE_MAX	LONG_MAX
+#define	fn		lroundf
+
+#include "s_lround.c"
Index: src/lib/libm/src/s_lroundl.c
diff -u /dev/null src/lib/libm/src/s_lroundl.c:1.1
--- /dev/null	Sat May  6 14:03:25 2017
+++ src/lib/libm/src/s_lroundl.c	Sat May  6 14:03:24 2017
@@ -0,0 +1,15 @@
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD: head/lib/msun/src/s_lroundl.c 144772 2005-04-08 01:24:08Z das $");
+#else
+__RCSID("$NetBSD: s_lroundl.c,v 1.1 2017/05/06 18:03:24 christos Exp $");
+#endif
+
+#define stype		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"

Reply via email to