aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/libm-ieee754
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/libm-ieee754')
-rw-r--r--sysdeps/libm-ieee754/s_nan.c47
-rw-r--r--sysdeps/libm-ieee754/s_nanf.c47
-rw-r--r--sysdeps/libm-ieee754/s_nanl.c48
-rw-r--r--sysdeps/libm-ieee754/s_nextafter.c2
-rw-r--r--sysdeps/libm-ieee754/s_nextafterf.c12
-rw-r--r--sysdeps/libm-ieee754/s_nextafterl.c2
-rw-r--r--sysdeps/libm-ieee754/s_remquo.c106
-rw-r--r--sysdeps/libm-ieee754/s_remquof.c105
-rw-r--r--sysdeps/libm-ieee754/s_remquol.c106
-rw-r--r--sysdeps/libm-ieee754/s_rintl.c4
-rw-r--r--sysdeps/libm-ieee754/s_trunc.c61
-rw-r--r--sysdeps/libm-ieee754/s_truncf.c52
-rw-r--r--sysdeps/libm-ieee754/s_truncl.c57
13 files changed, 639 insertions, 10 deletions
diff --git a/sysdeps/libm-ieee754/s_nan.c b/sysdeps/libm-ieee754/s_nan.c
new file mode 100644
index 0000000000..58551c1ad5
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_nan.c
@@ -0,0 +1,47 @@
+/* Return quiet nan.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* XXX The ISO C 9X standard mentions a `n-char-sequence' which is provided
+ as the argument to this function but I have no clue what this means.
+ Perhaps it is a description of the bits set in the mantissa. */
+#include <math.h>
+#ifdef HANDLE_TAGP
+# include <stdlib.h>
+# include <string.h>
+#else
+# include <ieee754.h>
+#endif
+
+
+double
+nan (const char *tagp)
+{
+#ifdef HANDLE_TAGP
+ /* If we ever should have use of the TAGP parameter we will use the
+ strtod function to analyze it. */
+ char buf[6 + strlen (tagp)];
+ sprintf (buf, "NAN(%s)", tagp);
+ return strtod (buf, NULL);
+#else
+ static const union ieee754_double nan_value =
+ { ieee: { mantissa1: 0x1, mantissa0: 0x0, exponent: 0x7ff, negative: 0 } };
+ return nan_value.d;
+#endif
+}
diff --git a/sysdeps/libm-ieee754/s_nanf.c b/sysdeps/libm-ieee754/s_nanf.c
new file mode 100644
index 0000000000..e965b94b33
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_nanf.c
@@ -0,0 +1,47 @@
+/* Return quiet nan.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* XXX The ISO C 9X standard mentions a `n-char-sequence' which is provided
+ as the argument to this function but I have no clue what this means.
+ Perhaps it is a description of the bits set in the mantissa. */
+#include <math.h>
+#ifdef HANDLE_TAGP
+# include <stdlib.h>
+# include <string.h>
+#else
+# include <ieee754.h>
+#endif
+
+
+float
+nanf (const char *tagp)
+{
+#ifdef HANDLE_TAGP
+ /* If we ever should have use of the TAGP parameter we will use the
+ strtod function to analyze it. */
+ char buf[6 + strlen (tagp)];
+ sprintf (buf, "NAN(%s)", tagp);
+ return strtof (buf, NULL);
+#else
+ static const union ieee754_float nan_value =
+ { ieee: { mantissa: 0x1, exponent: 0xff, negative: 0 } };
+ return nan_value.f;
+#endif
+}
diff --git a/sysdeps/libm-ieee754/s_nanl.c b/sysdeps/libm-ieee754/s_nanl.c
new file mode 100644
index 0000000000..df0180ee46
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_nanl.c
@@ -0,0 +1,48 @@
+/* Return quiet nan.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* XXX The ISO C 9X standard mentions a `n-char-sequence' which is provided
+ as the argument to this function but I have no clue what this means.
+ Perhaps it is a description of the bits set in the mantissa. */
+#include <math.h>
+#ifdef HANDLE_TAGP
+# include <stdlib.h>
+# include <string.h>
+#else
+# include <ieee754.h>
+#endif
+
+
+long double
+nanl (const char *tagp)
+{
+#ifdef HANDLE_TAGP
+ /* If we ever should have use of the TAGP parameter we will use the
+ strtod function to analyze it. */
+ char buf[6 + strlen (tagp)];
+ sprintf (buf, "NAN(%s)", tagp);
+ return strtold (buf, NULL);
+#else
+ static const union ieee854_long_double nan_value =
+ { ieee: { mantissa1: 0x1, mantissa0: 0x80000000,
+ exponent: 0x7fff, negative: 0 } };
+ return nan_value.d;
+#endif
+}
diff --git a/sysdeps/libm-ieee754/s_nextafter.c b/sysdeps/libm-ieee754/s_nextafter.c
index ee973bcee8..b98a161cf2 100644
--- a/sysdeps/libm-ieee754/s_nextafter.c
+++ b/sysdeps/libm-ieee754/s_nextafter.c
@@ -42,7 +42,7 @@ static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp
if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
return x+y;
- if(x==y) return x; /* x=y, return x */
+ if(x==y) return y; /* x=y, return y */
if((ix|lx)==0) { /* x == 0 */
INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
y = x*x;
diff --git a/sysdeps/libm-ieee754/s_nextafterf.c b/sysdeps/libm-ieee754/s_nextafterf.c
index bc8d04260f..611742bdf4 100644
--- a/sysdeps/libm-ieee754/s_nextafterf.c
+++ b/sysdeps/libm-ieee754/s_nextafterf.c
@@ -8,7 +8,7 @@
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
+ * software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
@@ -34,15 +34,15 @@ static char rcsid[] = "$NetBSD: s_nextafterf.c,v 1.4 1995/05/10 20:48:01 jtc Exp
ix = hx&0x7fffffff; /* |x| */
iy = hy&0x7fffffff; /* |y| */
- if((ix>0x7f800000) || /* x is nan */
- (iy>0x7f800000)) /* y is nan */
- return x+y;
- if(x==y) return x; /* x=y, return x */
+ if((ix>0x7f800000) || /* x is nan */
+ (iy>0x7f800000)) /* y is nan */
+ return x+y;
+ if(x==y) return y; /* x=y, return y */
if(ix==0) { /* x == 0 */
SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
y = x*x;
if(y==x) return y; else return x; /* raise underflow flag */
- }
+ }
if(hx>=0) { /* x > 0 */
if(hx>hy) { /* x > y, x -= ulp */
hx -= 1;
diff --git a/sysdeps/libm-ieee754/s_nextafterl.c b/sysdeps/libm-ieee754/s_nextafterl.c
index 0327261f33..1d3fc86c44 100644
--- a/sysdeps/libm-ieee754/s_nextafterl.c
+++ b/sysdeps/libm-ieee754/s_nextafterl.c
@@ -46,7 +46,7 @@ static char rcsid[] = "$NetBSD: $";
if(((ix==0x7fff)&&((hx|lx)|-(hx|lx))!=0) || /* x is nan */
((iy==0x7fff)&&((hy|ly)|-(hy|ly))!=0)) /* y is nan */
return x+y;
- if(x==y) return x; /* x=y, return x */
+ if(x==y) return y; /* x=y, return y */
if((ix|hx|lx)==0) { /* x == 0 */
SET_LDOUBLE_WORDS(x,esx&0x8000,0,1);/* return +-minsubnormal */
y = x*x;
diff --git a/sysdeps/libm-ieee754/s_remquo.c b/sysdeps/libm-ieee754/s_remquo.c
new file mode 100644
index 0000000000..5a96f75f3b
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_remquo.c
@@ -0,0 +1,106 @@
+/* Compute remainder and a congruent to the quotient.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. 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"
+
+
+static const double zero = 0.0;
+
+
+double
+__remquo (double x, double y, int *quo)
+{
+ int32_t hx,hp;
+ u_int32_t sx,lx,lp;
+ int cquo;
+
+ EXTRACT_WORDS (hx, lx, x);
+ EXTRACT_WORDS (hp, lp, p);
+ sx = hx & 0x80000000;
+ qs = (sx ^ (hp & 0x80000000)) >> 31;
+ hp &= 0x7fffffff;
+ hx &= 0x7fffffff;
+
+ /* Purge off exception values. */
+ if ((hp | lp) == 0)
+ return (x * p) / (x * p); /* p = 0 */
+ if ((hx >= 0x7ff00000) /* x not finite */
+ || ((hp >= 0x7ff00000) /* p is NaN */
+ && (((hp - 0x7ff00000) | lp) != 0)))
+ return (x * p) / (x * p);
+
+ if (hp <= 0x7fbfffff)
+ {
+ x = __ieee754_fmod (x, 8 * p); /* now x < 8p */
+
+ if (fabs (x) >= 4 * fabs (p))
+ cquo += 4;
+ }
+
+ if (((hx - hp) | (lx - lp)) == 0)
+ {
+ *quo = qs ? -1 : 1;
+ return zero * x;
+ }
+
+ x = fabs (x);
+ p = fabs (p);
+ cquo = 0;
+
+ if (x >= 2 * p)
+ {
+ x -= 4 * p;
+ cquo += 2;
+ }
+ if (x >= p)
+ {
+ x -= 2 * p;
+ ++cquo;
+ }
+
+ if (hp < 0x00200000)
+ {
+ if (x + x > p)
+ {
+ x -= p;
+ if (x + x >= p)
+ x -= p;
+ }
+ }
+ else
+ {
+ double p_half = 0.5 * p;
+ if(x > p_half)
+ {
+ x -= p;
+ if (x >= p_half)
+ x -= p;
+ }
+ }
+
+ *quo = qs ? -cquo : cquo;
+
+ GET_HIGH_WORD (hx, x);
+ SET_HIGH_WORD (x, hx ^ sx);
+ return x;
+}
+weak_alias (__remquo, remquo)
diff --git a/sysdeps/libm-ieee754/s_remquof.c b/sysdeps/libm-ieee754/s_remquof.c
new file mode 100644
index 0000000000..cce5495ce8
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_remquof.c
@@ -0,0 +1,105 @@
+/* Compute remainder and a congruent to the quotient.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. 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"
+
+
+static const float zero = 0.0;
+
+
+float
+__remquof (float x, float y, int *quo)
+{
+ int32_t hx,hp;
+ u_int32_t sx;
+ int cquo;
+
+ GET_FLOAT_WORD (hx, x);
+ GET_FLOAT_WORD (hp, p);
+ sx = hx & 0x80000000;
+ qs = (sx ^ (hp & 0x80000000)) >> 31;
+ hp &= 0x7fffffff;
+ hx &= 0x7fffffff;
+
+ /* Purge off exception values. */
+ if (hp == 0)
+ return (x * p) / (x * p); /* p = 0 */
+ if ((hx >= 0x7f800000) /* x not finite */
+ || (hp > 0x7f800000)) /* p is NaN */
+ return (x * p) / (x * p);
+
+ if (hp <= 0x7dffffff)
+ {
+ x = __ieee754_fmodf (x, 8 * p); /* now x < 8p */
+
+ if (fabs (x) >= 4 * fabs (p))
+ cquo += 4;
+ }
+
+ if ((hx - hp) == 0)
+ {
+ *quo = qs ? -1 : 1;
+ return zero * x;
+ }
+
+ x = fabsf (x);
+ p = fabsf (p);
+ cquo = 0;
+
+ if (x >= 2 * p)
+ {
+ x -= 4 * p;
+ cquo += 2;
+ }
+ if (x >= p)
+ {
+ x -= 2 * p;
+ ++cquo;
+ }
+
+ if (hp < 0x01000000)
+ {
+ if (x + x > p)
+ {
+ x -= p;
+ if (x + x >= p)
+ x -= p;
+ }
+ }
+ else
+ {
+ float p_half = 0.5 * p;
+ if(x > p_half)
+ {
+ x -= p;
+ if (x >= p_half)
+ x -= p;
+ }
+ }
+
+ *quo = qs ? -cquo : cquo;
+
+ GET_FLOAT_WORD (hx, x);
+ SET_FLOAT_WORD (x, hx ^ sx);
+ return x;
+}
+weak_alias (__remquof, remquof)
diff --git a/sysdeps/libm-ieee754/s_remquol.c b/sysdeps/libm-ieee754/s_remquol.c
new file mode 100644
index 0000000000..9515b218c6
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_remquol.c
@@ -0,0 +1,106 @@
+/* Compute remainder and a congruent to the quotient.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. 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"
+
+
+static const double zero = 0.0;
+
+
+long double
+__remquol (long double x, long double y, int *quo)
+{
+ int32_t ex,ep,hx,hp;
+ u_int32_t sx,lx,lp;
+ int cquo;
+
+ GET_LDOUBLE_WORDS (ex, hx, lx, x);
+ GET_LDOUBLE_WORDS (ep, hp, lp, p);
+ sx = ex & 0x8000;
+ qs = (sx ^ (ep & 0x8000)) >> 15;
+ ep &= 0x7fff;
+ ex &= 0x7fff;
+
+ /* Purge off exception values. */
+ if ((ep | hp | lp) == 0)
+ return (x * p) / (x * p); /* p = 0 */
+ if ((ex == 0x7fff) /* x not finite */
+ || ((ep == 0x7fff) /* p is NaN */
+ && ((hp | lp) != 0)))
+ return (x * p) / (x * p);
+
+ if (ep <= 0x7ffb)
+ {
+ x = __ieee754_fmodl (x, 8 * p); /* now x < 8p */
+
+ if (fabsl (x) >= 4 * fabsl (p))
+ cquo += 4;
+ }
+
+ if (((ex - ep) | (hx - hp) | (lx - lp)) == 0)
+ {
+ *quo = qs ? -1 : 1;
+ return zero * x;
+ }
+
+ x = fabsl (x);
+ p = fabsl (p);
+ cquo = 0;
+
+ if (x >= 2 * p)
+ {
+ x -= 4 * p;
+ cquo += 2;
+ }
+ if (x >= p)
+ {
+ x -= 2 * p;
+ ++cquo;
+ }
+
+ if (ep < 0x0002)
+ {
+ if (x + x > p)
+ {
+ x -= p;
+ if (x + x >= p)
+ x -= p;
+ }
+ }
+ else
+ {
+ long double p_half = 0.5 * p;
+ if(x > p_half)
+ {
+ x -= p;
+ if (x >= p_half)
+ x -= p;
+ }
+ }
+
+ *quo = qs ? -cquo : cquo;
+
+ GET_LDOUBLE_EXP (ex, x);
+ SET_LDOUBLE_EXP (x, ex ^ sx);
+ return x;
+}
+weak_alias (__remquol, remquol)
diff --git a/sysdeps/libm-ieee754/s_rintl.c b/sysdeps/libm-ieee754/s_rintl.c
index c9f12b162a..5b4b647880 100644
--- a/sysdeps/libm-ieee754/s_rintl.c
+++ b/sysdeps/libm-ieee754/s_rintl.c
@@ -54,7 +54,7 @@ TWO64[2]={
GET_LDOUBLE_WORDS(se,i0,i1,x);
sx = (se>>15)&1;
j0 = (se&0x7fff)-0x3fff;
- if(j0<32) {
+ if(j0<31) {
if(j0<0) {
if(((se&0x7fff)|i0|i1)==0) return x;
i1 |= i0;
@@ -67,7 +67,7 @@ TWO64[2]={
SET_LDOUBLE_EXP(t,(i0&0x7fff)|(sx<<15));
return t;
} else {
- i = (0xffffffff)>>j0;
+ i = (0x7fffffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
i>>=1;
if(((i0&i)|i1)!=0) {
diff --git a/sysdeps/libm-ieee754/s_trunc.c b/sysdeps/libm-ieee754/s_trunc.c
new file mode 100644
index 0000000000..721dce5a55
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_trunc.c
@@ -0,0 +1,61 @@
+/* Truncate argument to nearest integral value not larger than the argument.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. 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)
+{
+ int32_t i0, j0;
+ u_int32_t i1;
+ int sx;
+
+ EXTRACT_WORDS (i0, i1, x);
+ sx = i0 & 0x80000000;
+ j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
+ if (j0 < 20)
+ {
+ if (j0 < 0)
+ /* The magnitude of the number is < 1 so the result is +-0. */
+ INSERT_WORDS (x, sx, 0);
+ else
+ INSERT_WORDS (x, sx | i0 & ~(0x000fffff >> j0), 0);
+ }
+ else if (j0 > 51)
+ {
+ if (j0 == 0x400)
+ /* x is inf or NaN. */
+ return x + x;
+ }
+ else
+ {
+ INSERT_WORDS (x, i0, i1 & ~(0xffffffffu >> (j0 - 20)));
+ }
+
+ return x;
+}
+weak_alias (__trunc, trunc)
+#ifdef NO_LONG_DOUBLE
+strong_alias (__trunc, __truncl)
+weak_alias (__trunc, truncl)
+#endif
diff --git a/sysdeps/libm-ieee754/s_truncf.c b/sysdeps/libm-ieee754/s_truncf.c
new file mode 100644
index 0000000000..3e7b133c37
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_truncf.c
@@ -0,0 +1,52 @@
+/* Truncate argument to nearest integral value not larger than the argument.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. 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"
+
+
+float
+__truncf (float x)
+{
+ int32_t i0, j0;
+ int sx;
+
+ GET_FLOAT_WORD (i0, x);
+ sx = i0 & 0x80000000;
+ j0 = ((i0 >> 23) & 0xff) - 0x7f;
+ if (j0 < 23)
+ {
+ if (j0 < 0)
+ /* The magnitude of the number is < 1 so the result is +-0. */
+ SET_FLOAT_WORD (x, sx);
+ else
+ SET_FLOAT_WORD (x, sx | i0 & ~(0x007fffff >> j0));
+ }
+ else
+ {
+ if (j0 == 0x80)
+ /* x is inf or NaN. */
+ return x + x;
+ }
+
+ return x;
+}
+weak_alias (__truncf, truncf)
diff --git a/sysdeps/libm-ieee754/s_truncl.c b/sysdeps/libm-ieee754/s_truncl.c
new file mode 100644
index 0000000000..206eab2f22
--- /dev/null
+++ b/sysdeps/libm-ieee754/s_truncl.c
@@ -0,0 +1,57 @@
+/* Truncate argument to nearest integral value not larger than the argument.
+ Copyright (C) 1997 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. 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 double
+__truncl (long double x)
+{
+ int32_t i0, j0;
+ u_int32_t se, i1;
+ int sx;
+
+ GET_LDOUBLE_WORDS (se, i0, i1, x);
+ sx = se & 0x8000;
+ j0 = se & 0x7fff;
+ if (j0 < 31)
+ {
+ if (j0 < 0)
+ /* The magnitude of the number is < 1 so the result is +-0. */
+ SET_LDOUBLE_WORDS (x, sx, 0, 0);
+ else
+ SET_LDOUBLE_WORDS (x, se, i0 & ~(0x7fffffff >> j0), 0);
+ }
+ else if (j0 > 63)
+ {
+ if (j0 == 0x4000)
+ /* x is inf or NaN. */
+ return x + x;
+ }
+ else
+ {
+ SET_LDOUBLE_WORDS (x, se, i0, i1 & ~(0xffffffffu >> (j0 - 31)));
+ }
+
+ return x;
+}
+weak_alias (__truncl, truncl)