]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix overflow handling in fdim.
authorUlrich Drepper <drepper@redhat.com>
Mon, 24 Aug 2009 19:06:55 +0000 (12:06 -0700)
committerUlrich Drepper <drepper@redhat.com>
Mon, 24 Aug 2009 19:06:55 +0000 (12:06 -0700)
ChangeLog
math/s_fdim.c
math/s_fdimf.c
math/s_fdiml.c

index b367ab07826f5c0dd67c782f26e1978061c56233..76a0d1dd06f5ebac193174bc60e1ea36d103a47d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-08-24  Ulrich Drepper  <drepper@redhat.com>
 
+       * math/s_fdim.c: In case of overflows set errno.
+       * math/s_fdimf.c: Likewise.
+       * math/s_fdiml.c: Likewise.
+
        * math/math.h: Define math_errhandling of __FAST_MATH__ is not defined.
        * sysdeps/i386/fpu/bits/mathinline.h: Undefine math_errhandling if we
        are using the inline optimizations.
index 5804e631c376f83bb84d5dba0a7bd34adee463d2..677fdcde1a505b26f75d9e2e200f8b57eda3af89 100644 (file)
@@ -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
index 2f3ce303ae869b6c0b093402fd9065039cfd5bb0..737413a5f4a1004954f8aaec164acf4084a0c15f 100644 (file)
@@ -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)
index 70246bafbdb66f2253f03f4c1230226133957aa6..e1ff11b307ed6b616181d30c464b28a9872d12db 100644 (file)
@@ -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.
 
    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)