summaryrefslogtreecommitdiff
path: root/libm/s_fdim.c
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2015-03-29 04:50:56 -0500
committerWaldemar Brodkorb <wbx@openadk.org>2015-03-29 04:50:56 -0500
commitcd5f92704e1e17bbc0c15d197f3bc236c7dc9bf2 (patch)
tree1400302b543e4528aedea5d72731983559cfcf36 /libm/s_fdim.c
parentad2bffbf1926051ef333f9899344f6bddf2c03cf (diff)
parent24946289317ea23bb0d1814cca0a499a905f7d6f (diff)
merge uClibc git master
Diffstat (limited to 'libm/s_fdim.c')
-rw-r--r--libm/s_fdim.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/libm/s_fdim.c b/libm/s_fdim.c
index 6249219c8..6ed695c3d 100644
--- a/libm/s_fdim.c
+++ b/libm/s_fdim.c
@@ -6,13 +6,22 @@
#include "math.h"
#include "math_private.h"
+#include <errno.h>
double fdim(double x, double y)
{
- int c = __fpclassify(x);
- if (c == FP_NAN || c == FP_INFINITE)
- return HUGE_VAL;
+ int cx = __fpclassify(x); /* need both NAN and INF */
+ int cy = __fpclassify(y); /* need both NAN and INF */
+ if (cx == FP_NAN || cy == NAN)
+ return x - y;
- return x > y ? x - y : 0.0;
+ if (x <= y)
+ return .0;
+
+ double z = x - y;
+ if (isinf(z) && cx != FP_INFINITE && cy != FP_INFINITE)
+ __set_errno(ERANGE);
+
+ return z;
}
libm_hidden_def(fdim)