summaryrefslogtreecommitdiff
path: root/libm/s_fdim.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2015-03-18 22:32:22 +0100
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2015-03-18 22:32:22 +0100
commit6c4538905e65ceb203f59aaa9a61728e81c6bc0a (patch)
tree241337035488fb2b179340d79a5ec4539f5fc09a /libm/s_fdim.c
parent78e6494c2cf677d170a5c4ce0f46d152d478abc0 (diff)
libm: Add missing C99 float/ld wrappers
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
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)