about summary refs log tree commit diff
path: root/math/s_fdimf.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-08-24 12:06:55 -0700
committerUlrich Drepper <drepper@redhat.com>2009-08-24 12:06:55 -0700
commitf0c281e072fd324261a51558284c04e230c0178d (patch)
tree1934177724689ef72853bdb7490648034eef7cb1 /math/s_fdimf.c
parent7b943af6cf2bfd4b94be271877a10128c32d03da (diff)
downloadglibc-f0c281e072fd324261a51558284c04e230c0178d.tar.gz
glibc-f0c281e072fd324261a51558284c04e230c0178d.tar.xz
glibc-f0c281e072fd324261a51558284c04e230c0178d.zip
Fix overflow handling in fdim.
Diffstat (limited to 'math/s_fdimf.c')
-rw-r--r--math/s_fdimf.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/math/s_fdimf.c b/math/s_fdimf.c
index 2f3ce303ae..737413a5f4 100644
--- a/math/s_fdimf.c
+++ b/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)