about summary refs log tree commit diff
path: root/sysdeps/ieee754
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2015-06-23 17:26:46 +0000
committerJoseph Myers <joseph@codesourcery.com>2015-06-23 17:26:46 +0000
commit8b1bab5ffa235bc494c33fdbe4c9994202936cfc (patch)
tree0eb0ae14f2fef3c11c2a055e155f61458f1ff2fe /sysdeps/ieee754
parentc47ca9647f9b72692e62f94fe468cd5568f49129 (diff)
downloadglibc-8b1bab5ffa235bc494c33fdbe4c9994202936cfc.tar.gz
glibc-8b1bab5ffa235bc494c33fdbe4c9994202936cfc.tar.xz
glibc-8b1bab5ffa235bc494c33fdbe4c9994202936cfc.zip
Fix spurious "inexact" exceptions from __kernel_standard_l (bug 18245, bug 18583).
__kernel_standard_l converts long double arguments to double for use
in SVID "struct exception".  This has special-case handling for when
that conversion would overflow or underflow but the original long
double function wouldn't.  However, it turns out that "inexact"
exceptions can be spurious here as well, when the function is exactly
determined and __kernel_standard_l is being called for a domain error.
This patch fixes this by using feholdexcept / fesetenv to avoid
exceptions from the conversion, replacing the previous special-case
logic for overflow and underflow (this covers all functions using
__kernel_standard_l, not just those that actually need a change, since
there doesn't seem to be much point in restricting things just to the
functions that mustn't get "inexact" here).

Tested for x86_64 and x86.

	[BZ #18245]
	[BZ #18583]
	* sysdeps/ieee754/k_standardl.c: Include <fenv.h>.
	(__kernel_standard_l): Use feholdexcept and fesetenv around
	conversion to double instead of special-casing overflow and
	underflow.
	* math/libm-test.inc (fmod_test_data): Add more tests.
	(remainder_test_data): Likewise.
	(sqrt_test_data): Likewise.
Diffstat (limited to 'sysdeps/ieee754')
-rw-r--r--sysdeps/ieee754/k_standardl.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/sysdeps/ieee754/k_standardl.c b/sysdeps/ieee754/k_standardl.c
index eaa2f661f1..aa95748825 100644
--- a/sysdeps/ieee754/k_standardl.c
+++ b/sysdeps/ieee754/k_standardl.c
@@ -32,6 +32,7 @@
 
 #include <math.h>
 #include <math_private.h>
+#include <fenv.h>
 #include <float.h>
 #include <errno.h>
 
@@ -47,31 +48,14 @@ __kernel_standard_l (long double x, long double y, int type)
 {
   double dx, dy;
   struct exception exc;
+  fenv_t env;
 
-  if (isfinite (x))
-    {
-      long double ax = fabsl (x);
-      if (ax > DBL_MAX)
-	dx = __copysignl (DBL_MAX, x);
-      else if (ax > 0 && ax < DBL_MIN)
-	dx = __copysignl (DBL_MIN, x);
-      else
-	dx = x;
-    }
-  else
-    dx = x;
-  if (isfinite (y))
-    {
-      long double ay = fabsl (y);
-      if (ay > DBL_MAX)
-	dy = __copysignl (DBL_MAX, y);
-      else if (ay > 0 && ay < DBL_MIN)
-	dy = __copysignl (DBL_MIN, y);
-      else
-	dy = y;
-    }
-  else
-    dy = y;
+  feholdexcept (&env);
+  dx = x;
+  dy = y;
+  math_force_eval (dx);
+  math_force_eval (dy);
+  fesetenv (&env);
 
   switch (type)
     {