diff options
author | Ulrich Drepper <drepper@redhat.com> | 1997-03-23 01:54:07 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1997-03-23 01:54:07 +0000 |
commit | bc9f6000f6752153e5e1902259d5f491a88a1ae5 (patch) | |
tree | affff963d9f44f476e13e4ee673f67509456096f /sysdeps/libm-ieee754 | |
parent | 5ae9d168f66cc6b40f74cfb4a8f2631fc1df6a2a (diff) | |
download | glibc-bc9f6000f6752153e5e1902259d5f491a88a1ae5.tar.gz glibc-bc9f6000f6752153e5e1902259d5f491a88a1ae5.tar.xz glibc-bc9f6000f6752153e5e1902259d5f491a88a1ae5.zip |
Update. cvs/libc-ud-970322
1997-03-23 02:11 Ulrich Drepper <drepper@cygnus.com> * time/sys/time.h: Make values ITIMER_* also available as macros. * elf/dl-support.c (_dl_sysdep_read_whole_file): Don't call __fstat but instead __fxstat directly to avoid dependency on libc.a when inline failed. * sysdeps/generic/dl-sysdep.c (_dl_sysdep_read_whole_file): Likewise. * math/Makefile (libm-routines): Add s_remquo. * sysdeps/libm-i387/s_remquo.S: New file. * sysdeps/libm-i387/s_remquof.S: New file. * sysdeps/libm-i387/s_remquol.S: New file. * sysdeps/libm-ieee754/s_remquo.c: New file. * sysdeps/libm-ieee754/s_remquof.c: New file. * sysdeps/libm-ieee754/s_remquol.c: New file. * math/libm-test.c (remquo_test): New function. * sysdeps/libm-ieee754/s_rintl.c: Handle implicit leading one correctly. 1997-03-22 14:06 Ulrich Drepper <drepper@cygnus.com> * math/Makefile (libm-calls): Add s_nan. * sysdeps/libm-ieee754/s_nan.c: New file. Implement `nan' function. * sysdeps/libm-ieee754/s_nanf.c: New file. Implement `nanf' function. * sysdeps/libm-ieee754/s_nanl.c: New file. Implement `nanl' function. * math/libm-test.c (basic_tests): Add tests for `nan' function. * math/libm-test.c (copysign_test): New function. (main): Call copysign_test. 1997-03-22 06:28 Ulrich Drepper <drepper@cygnus.com> * sysdeps/libm-ieee754/s_nextafter.c: Return y if x == y. * sysdeps/libm-ieee754/s_nextafterf.c: Likewise. * sysdeps/libm-ieee754/s_nextafterl.c: Likewise. * sysdeps/libm-i387/s_nextafterl.c: Likewise. * math/libm-test.c (fdim_test, fmin_test, fmax_test, nextafter_test): New functions. Test these functions. (main): Call above new functions. 1997-03-22 04:53 Ulrich Drepper <drepper@cygnus.com> * Net release 2.0.2. 1997-03-22 04:37 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/termbits.h (OXTABS): Define as alias for XTABS. * sysdeps/unix/sysv/linux/alpha/termbits.h (OXTABS): Likewise. * termios/sys/ttydefaults.h: Partly revert patch by Andreas Schwab of Sun Dec 15 16:33:44 1996. Proposed by Thomas Bushnell <thomas@gnu.ai.mit.edu>. 1997-03-21 13:41 Roland McGrath <roland@baalperazim.frob.com> * sysdeps/sparc/dl-machine.h (elf_machine_rel): Rewritten as for i386. Check here for non-SHN_UNDEF STB_LOCAL symbols don't do any lookup or consult their values. (elf_machine_lookup_noexec_p, elf_machine_lookup_noplt_p, ELF_MACHINE_RELOC_NOPLT): New macros. * elf/rtld.c (dl_main): Pass ELF_MACHINE_RELOC_NOPLT to _dl_lookup_symbol in place of DL_LOOKUP_NOPLT. * sysdeps/i386/dl-machine.h (ELF_MACHINE_RELOC_NOPLT): New macro. * sysdeps/i386/dl-machine.h (elf_machine_rel): Rewritten to do the symbol lookup before checking reloc type except for R_386_RELATIVE. (elf_machine_lookup_noexec_p, elf_machine_lookup_noplt_p): New macros. * elf/dl-reloc.c (RESOLVE): Remove STB_LOCAL check; let it be per-machine since it supposedly can't happen on i386. * elf/dl-lookup.c (do_lookup): Change arg FLAGS to RELOC_TYPE. Use elf_machine_lookup_{noexec,noplt}_p macros on it. Remove gratuitous indirection from REF arg; change callers. (_dl_lookup_symbol, _dl_lookup_versioned_symbol): Change arg name. (_dl_lookup_symbol_skip, _dl_lookup_versioned_symbol_skip): Remove FLAGS arg altogether. * elf/dlsym.c: Remove argument of FLAGS parameter. * elf/dlvsym.c: Likewise. * elf/link.h: Update decls. * Makefile (distribute): Add BUGS.
Diffstat (limited to 'sysdeps/libm-ieee754')
-rw-r--r-- | sysdeps/libm-ieee754/s_nan.c | 47 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_nanf.c | 47 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_nanl.c | 48 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_nextafter.c | 2 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_nextafterf.c | 12 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_nextafterl.c | 2 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_remquo.c | 106 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_remquof.c | 105 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_remquol.c | 106 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_rintl.c | 4 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_trunc.c | 61 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_truncf.c | 52 | ||||
-rw-r--r-- | sysdeps/libm-ieee754/s_truncl.c | 57 |
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) |