diff options
author | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2009-08-25 15:16:23 +0000 |
---|---|---|
committer | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2009-08-25 15:16:23 +0000 |
commit | 36ee53dd0120e48bab5f6793e149d3b4df6fb3ee (patch) | |
tree | 1fe31a4c64b9d4225e96674a5f5b9dc2fab6fba4 /libc/math | |
parent | 5aa1a5ac2772b35cf67fa77bdb37a0423876f820 (diff) | |
download | eglibc2-36ee53dd0120e48bab5f6793e149d3b4df6fb3ee.tar.gz |
Merge changes between r8789 and r8871 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@8872 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/math')
-rw-r--r-- | libc/math/math.h | 11 | ||||
-rw-r--r-- | libc/math/math_private.h | 19 | ||||
-rw-r--r-- | libc/math/s_fdim.c | 12 | ||||
-rw-r--r-- | libc/math/s_fdimf.c | 12 | ||||
-rw-r--r-- | libc/math/s_fdiml.c | 16 |
5 files changed, 60 insertions, 10 deletions
diff --git a/libc/math/math.h b/libc/math/math.h index c50b2e7b0..4e65678b8 100644 --- a/libc/math/math.h +++ b/libc/math/math.h @@ -1,5 +1,5 @@ /* Declarations for math functions. - Copyright (C) 1991-1993, 1995-1999, 2001, 2002, 2004, 2006 + Copyright (C) 1991-1993, 1995-1999, 2001, 2002, 2004, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -101,7 +101,7 @@ __BEGIN_DECLS && (!defined __NO_LONG_DOUBLE_MATH || defined __LDBL_COMPAT) # ifdef __LDBL_COMPAT -# ifdef __USE_ISOC99 +# ifdef __USE_ISOC99 extern float __nldbl_nexttowardf (float __x, long double __y) __THROW __attribute__ ((__const__)); # ifdef __REDIRECT_NTH @@ -277,6 +277,13 @@ enum # define MATH_ERRNO 1 /* errno set by math functions. */ # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */ +/* By default all functions support both errno and exception handling. + In gcc's fast math mode and if inline functions are defined this + might not be true. */ +# ifndef __FAST_MATH__ +# define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT) +# endif + #endif /* Use ISO C99. */ #ifdef __USE_MISC diff --git a/libc/math/math_private.h b/libc/math/math_private.h index 129646f8c..fade7e118 100644 --- a/libc/math/math_private.h +++ b/libc/math/math_private.h @@ -17,6 +17,7 @@ #define _MATH_PRIVATE_H_ #include <endian.h> +#include <stdint.h> #include <sys/types.h> /* The original fdlibm code used statements like: @@ -43,6 +44,7 @@ typedef union u_int32_t msw; u_int32_t lsw; } parts; + uint64_t word; } ieee_double_shape_type; #endif @@ -57,6 +59,7 @@ typedef union u_int32_t lsw; u_int32_t msw; } parts; + uint64_t word; } ieee_double_shape_type; #endif @@ -89,6 +92,14 @@ do { \ (i) = gl_u.parts.lsw; \ } while (0) +/* Get all in one, efficient on 64-bit machines. */ +#define EXTRACT_WORDS64(i,d) \ +do { \ + ieee_double_shape_type gh_u; \ + gh_u.value = (d); \ + (i) = gh_u.word; \ +} while (0) + /* Set a double from two 32 bit ints. */ #define INSERT_WORDS(d,ix0,ix1) \ @@ -99,6 +110,14 @@ do { \ (d) = iw_u.value; \ } while (0) +/* Get all in one, efficient on 64-bit machines. */ +#define INSERT_WORDS64(i,d) \ +do { \ + ieee_double_shape_type iw_u; \ + iw_u.word = (i); \ + (d) = iw_u.value; \ +} while (0) + /* Set the more significant 32 bits of a double from an int. */ #define SET_HIGH_WORD(d,v) \ diff --git a/libc/math/s_fdim.c b/libc/math/s_fdim.c index 5804e631c..677fdcde1 100644 --- a/libc/math/s_fdim.c +++ b/libc/math/s_fdim.c @@ -1,5 +1,5 @@ /* Return positive difference between arguments. - Copyright (C) 1997, 2004 Free Software Foundation, Inc. + 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. @@ -18,6 +18,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <errno.h> #include <math.h> double @@ -31,7 +32,14 @@ __fdim (double x, double y) /* Raise invalid flag. */ return x - y; - return x <= y ? 0 : x - y; + if (x <= y) + return 0.0; + + double r = x - y; + if (fpclassify (r) == FP_INFINITE) + __set_errno (ERANGE); + + return r; } weak_alias (__fdim, fdim) #ifdef NO_LONG_DOUBLE diff --git a/libc/math/s_fdimf.c b/libc/math/s_fdimf.c index 2f3ce303a..737413a5f 100644 --- a/libc/math/s_fdimf.c +++ b/libc/math/s_fdimf.c @@ -1,5 +1,5 @@ /* Return positive difference between arguments. - Copyright (C) 1997, 2004 Free Software Foundation, Inc. + 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. @@ -18,6 +18,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <errno.h> #include <math.h> float @@ -31,6 +32,13 @@ __fdimf (float x, float y) /* Raise invalid flag. */ return x - y; - return x <= y ? 0 : x - y; + if (x <= y) + return 0.0f; + + float r = x - y; + if (fpclassify (r) == FP_INFINITE) + __set_errno (ERANGE); + + return r; } weak_alias (__fdimf, fdimf) diff --git a/libc/math/s_fdiml.c b/libc/math/s_fdiml.c index 70246bafb..e1ff11b30 100644 --- a/libc/math/s_fdiml.c +++ b/libc/math/s_fdiml.c @@ -1,5 +1,5 @@ /* Return positive difference between arguments. - Copyright (C) 1997, 2004 Free Software Foundation, Inc. + 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. @@ -18,19 +18,27 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <errno.h> #include <math.h> long double __fdiml (long double x, long double y) { - int clsx = fpclassify (x); - int clsy = fpclassify (y); + int clsx = fpclassifyl (x); + int clsy = fpclassifyl (y); if (clsx == FP_NAN || clsy == FP_NAN || (y < 0 && clsx == FP_INFINITE && clsy == FP_INFINITE)) /* Raise invalid flag. */ return x - y; - return x <= y ? 0 : x - y; + if (x <= y) + return 0.0f; + + long double r = x - y; + if (fpclassify (r) == FP_INFINITE) + __set_errno (ERANGE); + + return r; } weak_alias (__fdiml, fdiml) |