diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2015-03-29 04:50:56 -0500 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2015-03-29 04:50:56 -0500 |
commit | cd5f92704e1e17bbc0c15d197f3bc236c7dc9bf2 (patch) | |
tree | 1400302b543e4528aedea5d72731983559cfcf36 /libm/s_fdim.c | |
parent | ad2bffbf1926051ef333f9899344f6bddf2c03cf (diff) | |
parent | 24946289317ea23bb0d1814cca0a499a905f7d6f (diff) |
merge uClibc git master
Diffstat (limited to 'libm/s_fdim.c')
-rw-r--r-- | libm/s_fdim.c | 17 |
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) |