X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmath%2Fnextafterf.c;h=75a09f7d1cf115d9a5d5dfeda9b12d42de269904;hb=a2a328bd896fa909542b492601e3689119b95de0;hp=4727f7b0385141f1d6221e763cbb48b496f5220e;hpb=6cf865dba69bab6346dc268d9173609af36b984e;p=musl diff --git a/src/math/nextafterf.c b/src/math/nextafterf.c index 4727f7b0..75a09f7d 100644 --- a/src/math/nextafterf.c +++ b/src/math/nextafterf.c @@ -1,35 +1,30 @@ #include "libm.h" -#define SIGN 0x80000000 - float nextafterf(float x, float y) { - union fshape ux, uy; + union {float f; uint32_t i;} ux={x}, uy={y}; uint32_t ax, ay, e; if (isnan(x) || isnan(y)) return x + y; - ux.value = x; - uy.value = y; - if (ux.bits == uy.bits) + if (ux.i == uy.i) return y; - ax = ux.bits & ~SIGN; - ay = uy.bits & ~SIGN; + ax = ux.i & 0x7fffffff; + ay = uy.i & 0x7fffffff; if (ax == 0) { if (ay == 0) return y; - ux.bits = (uy.bits & SIGN) | 1; - } else if (ax > ay || ((ux.bits ^ uy.bits) & SIGN)) - ux.bits--; + ux.i = (uy.i & 0x80000000) | 1; + } else if (ax > ay || ((ux.i ^ uy.i) & 0x80000000)) + ux.i--; else - ux.bits++; - e = ux.bits & 0x7f800000; - /* raise overflow if ux.value is infinite and x is finite */ + ux.i++; + e = ux.i & 0x7f800000; + /* raise overflow if ux.f is infinite and x is finite */ if (e == 0x7f800000) - return x + x; - /* raise underflow if ux.value is subnormal or zero */ - if (e == 0) { - volatile float z = x*x + ux.value*ux.value; - } - return ux.value; + FORCE_EVAL(x+x); + /* raise underflow if ux.f is subnormal or zero */ + if (e == 0) + FORCE_EVAL(x*x + ux.f*ux.f); + return ux.f; }