summaryrefslogtreecommitdiff
path: root/libc/sysdeps/ieee754/dbl-64
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2009-08-26 02:17:41 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2009-08-26 02:17:41 +0000
commit5ae64e3ae4a65a25176fe6b5d34946f49fd9d910 (patch)
tree4990366ff3aef5697991716d40abf5ef480a725e /libc/sysdeps/ieee754/dbl-64
parent1e6f82111b008a12c23b5c64060b8f13b049ce4b (diff)
Merge changes between r8871 and r8878 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@8879 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/sysdeps/ieee754/dbl-64')
-rw-r--r--libc/sysdeps/ieee754/dbl-64/wordsize-64/s_lround.c67
-rw-r--r--libc/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c68
-rw-r--r--libc/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c56
3 files changed, 191 insertions, 0 deletions
diff --git a/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_lround.c b/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_lround.c
new file mode 100644
index 000000000..2df169ead
--- /dev/null
+++ b/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_lround.c
@@ -0,0 +1,67 @@
+/* Round double value to long int.
+ Copyright (C) 1997, 2004, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+long int
+__lround (double x)
+{
+ int32_t j0;
+ int64_t i0;
+ long int result;
+ int sign;
+
+ EXTRACT_WORDS64 (i0, x);
+ j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
+ sign = i0 < 0 ? -1 : 1;
+ i0 &= UINT64_C(0xfffffffffffff);
+ i0 |= UINT64_C(0x10000000000000);
+
+ if (j0 < (int32_t) (8 * sizeof (long int)) - 1)
+ {
+ if (j0 < 0)
+ return j0 < -1 ? 0 : sign;
+ else if (j0 >= 52)
+ result = i0 << (j0 - 52);
+ else
+ {
+ i0 += UINT64_C(0x8000000000000) >> j0;
+
+ result = i0 >> (52 - j0);
+ }
+ }
+ else
+ {
+ /* The number is too large. It is left implementation defined
+ what happens. */
+ return (long int) x;
+ }
+
+ return sign * result;
+}
+
+weak_alias (__lround, lround)
+#ifdef NO_LONG_DOUBLE
+strong_alias (__lround, __lroundl)
+weak_alias (__lround, lroundl)
+#endif
diff --git a/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c b/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c
new file mode 100644
index 000000000..25cf3b169
--- /dev/null
+++ b/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c
@@ -0,0 +1,68 @@
+/* @(#)s_scalbn.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * scalbn (double x, int n)
+ * scalbn(x,n) returns x* 2**n computed by exponent
+ * manipulation rather than by actually performing an
+ * exponentiation or a multiplication.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+#ifdef __STDC__
+static const double
+#else
+static double
+#endif
+two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
+huge = 1.0e+300,
+tiny = 1.0e-300;
+
+#ifdef __STDC__
+ double __scalbn (double x, int n)
+#else
+ double __scalbn (x,n)
+ double x; int n;
+#endif
+{
+ int64_t ix;
+ int64_t k;
+ EXTRACT_WORDS64(ix,x);
+ k = (ix >> 52) & 0x7ff; /* extract exponent */
+ if (k==0) { /* 0 or subnormal x */
+ if ((ix & UINT64_C(0xfffffffffffff))==0) return x; /* +-0 */
+ x *= two54;
+ EXTRACT_WORDS64(ix,x);
+ k = ((ix >> 52) & 0x7ff) - 54;
+ }
+ if (k==0x7ff) return x+x; /* NaN or Inf */
+ k = k+n;
+ if (n> 50000 || k > 0x7fe)
+ return huge*__copysign(huge,x); /* overflow */
+ if (n< -50000) return tiny*__copysign(tiny,x); /*underflow*/
+ if (k > 0) /* normal result */
+ {INSERT_WORDS64(x,(ix&UINT64_C(0x800fffffffffffff))|(k<<52));
+ return x;}
+ if (k <= -54)
+ return tiny*__copysign(tiny,x); /*underflow*/
+ k += 54; /* subnormal result */
+ INSERT_WORDS64(x,(ix&INT64_C(0x800fffffffffffff))|(k<<52));
+ return x*twom54;
+}
+weak_alias (__scalbn, scalbn)
+#ifdef NO_LONG_DOUBLE
+strong_alias (__scalbn, __scalbnl)
+weak_alias (__scalbn, scalbnl)
+#endif
diff --git a/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c b/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
new file mode 100644
index 000000000..9add5ade7
--- /dev/null
+++ b/libc/sysdeps/ieee754/dbl-64/wordsize-64/s_trunc.c
@@ -0,0 +1,56 @@
+/* Truncate argument to nearest integral value not larger than the argument.
+ Copyright (C) 1997, 1998, 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+double
+__trunc (double x)
+{
+ int64_t i0, j0;
+ int64_t sx;
+
+ EXTRACT_WORDS64 (i0, x);
+ sx = i0 & UINT64_C(0x8000000000000000);
+ j0 = ((i0 >> 52) & 0x7ff) - 0x3ff;
+ if (j0 < 52)
+ {
+ if (j0 < 0)
+ /* The magnitude of the number is < 1 so the result is +-0. */
+ INSERT_WORDS64 (x, sx);
+ else
+ INSERT_WORDS64 (x, sx | (i0 & ~(UINT64_C(0x000fffffffffffff) >> j0)));
+ }
+ else
+ {
+ if (j0 == 0x400)
+ /* x is inf or NaN. */
+ return x + x;
+ }
+
+ return x;
+}
+weak_alias (__trunc, trunc)
+#ifdef NO_LONG_DOUBLE
+strong_alias (__trunc, __truncl)
+weak_alias (__trunc, truncl)
+#endif