summaryrefslogtreecommitdiffstats
path: root/lib/msun/src
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2008-01-14 02:12:07 +0000
committerdas <das@FreeBSD.org>2008-01-14 02:12:07 +0000
commit4f45aea521bd20b04ffc664d0990d604a6db4b53 (patch)
treee7d4ceb39742f3b8c03c4306fbde27889c1eba60 /lib/msun/src
parent1b5d4e71ef50fdd1f3bc9124633a821409dc0663 (diff)
downloadFreeBSD-src-4f45aea521bd20b04ffc664d0990d604a6db4b53.zip
FreeBSD-src-4f45aea521bd20b04ffc664d0990d604a6db4b53.tar.gz
Implement rintl(), nearbyintl(), lrintl(), and llrintl().
Thanks to bde@ for feedback and testing of rintl().
Diffstat (limited to 'lib/msun/src')
-rw-r--r--lib/msun/src/math.h8
-rw-r--r--lib/msun/src/s_llrintl.c9
-rw-r--r--lib/msun/src/s_lrintl.c9
-rw-r--r--lib/msun/src/s_nearbyint.c1
-rw-r--r--lib/msun/src/s_rint.c6
-rw-r--r--lib/msun/src/s_rintl.c77
6 files changed, 105 insertions, 5 deletions
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h
index 9f791ae0..07bbd57 100644
--- a/lib/msun/src/math.h
+++ b/lib/msun/src/math.h
@@ -429,8 +429,8 @@ int ilogbl(long double) __pure2;
long double ldexpl(long double, int);
#if 0
long double lgammal(long double);
-long long llrintl(long double);
#endif
+long long llrintl(long double);
long long llroundl(long double);
#if 0
long double log10l(long double);
@@ -440,14 +440,12 @@ long double log2l(long double);
long double logbl(long double);
#if 0
long double logl(long double);
-long lrintl(long double);
#endif
+long lrintl(long double);
long lroundl(long double);
long double modfl(long double, long double *); /* fundamentally !__pure2 */
long double nanl(const char *) __pure2;
-#if 0
long double nearbyintl(long double);
-#endif
long double nextafterl(long double, long double);
double nexttoward(double, long double);
float nexttowardf(float, long double);
@@ -456,8 +454,8 @@ long double nexttowardl(long double, long double);
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);
#endif
+long double rintl(long double);
long double roundl(long double);
long double scalblnl(long double, long);
long double scalbnl(long double, int);
diff --git a/lib/msun/src/s_llrintl.c b/lib/msun/src/s_llrintl.c
new file mode 100644
index 0000000..6ef8375
--- /dev/null
+++ b/lib/msun/src/s_llrintl.c
@@ -0,0 +1,9 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type long double
+#define roundit rintl
+#define dtype long long
+#define fn llrintl
+
+#include "s_lrint.c"
diff --git a/lib/msun/src/s_lrintl.c b/lib/msun/src/s_lrintl.c
new file mode 100644
index 0000000..497b442
--- /dev/null
+++ b/lib/msun/src/s_lrintl.c
@@ -0,0 +1,9 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type long double
+#define roundit rintl
+#define dtype long
+#define fn lrintl
+
+#include "s_lrint.c"
diff --git a/lib/msun/src/s_nearbyint.c b/lib/msun/src/s_nearbyint.c
index a075d2f..12493d29 100644
--- a/lib/msun/src/s_nearbyint.c
+++ b/lib/msun/src/s_nearbyint.c
@@ -52,3 +52,4 @@ fn(type x) \
DECL(double, nearbyint, rint)
DECL(float, nearbyintf, rintf)
+DECL(long double, nearbyintl, rintl)
diff --git a/lib/msun/src/s_rint.c b/lib/msun/src/s_rint.c
index 0a7bfc4..74a9331 100644
--- a/lib/msun/src/s_rint.c
+++ b/lib/msun/src/s_rint.c
@@ -24,6 +24,8 @@ static char rcsid[] = "$FreeBSD$";
* Inexact flag raised if x not equal to rint(x).
*/
+#include <float.h>
+
#include "math.h"
#include "math_private.h"
@@ -85,3 +87,7 @@ rint(double x)
*(volatile double *)&w = TWO52[sx]+x; /* clip any extra precision */
return w-TWO52[sx];
}
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(rint, rintl);
+#endif
diff --git a/lib/msun/src/s_rintl.c b/lib/msun/src/s_rintl.c
new file mode 100644
index 0000000..21dbbf6
--- /dev/null
+++ b/lib/msun/src/s_rintl.c
@@ -0,0 +1,77 @@
+/*-
+ * Copyright (c) 2008 David Schultz <das@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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+#include <math.h>
+
+#include "fpmath.h"
+
+static const long double
+shift[2]={
+#if LDBL_MANT_DIG == 64
+ 0x1.0p63, -0x1.0p63
+#elif LDBL_MANT_DIG == 113
+ 0x1.0p112, -0x1.0p112
+#else
+#error "Unsupported long double format"
+#endif
+};
+
+long double
+rintl(long double x)
+{
+ union IEEEl2bits u;
+ short sign;
+
+ u.e = x;
+
+ if (u.bits.exp >= LDBL_MANT_DIG + LDBL_MAX_EXP - 2) {
+ /*
+ * The biased exponent is greater than the number of digits
+ * in the mantissa, so x is inf, NaN, or an integer.
+ */
+ if (u.bits.exp == 2 * LDBL_MAX_EXP - 1)
+ return (x + x); /* inf or NaN */
+ else
+ return (x);
+ }
+
+ /*
+ * The following code assumes that intermediate results are
+ * evaluated in long double precision. If they are evaluated in
+ * greater precision, double rounding will occur, and if they are
+ * evaluated in less precision (as on i386), results will be
+ * wildly incorrect.
+ */
+ sign = u.bits.sign;
+ u.e = shift[sign] + x;
+ u.e -= shift[sign];
+ u.bits.sign = sign;
+ return (u.e);
+}
OpenPOWER on IntegriCloud