1 #include "libm.h" 2 nexttowardf(float x,long double y)3float nexttowardf(float x, long double y) 4 { 5 union {float f; uint32_t i;} ux = {x}; 6 uint32_t e; 7 8 if (isnan(x) || isnan(y)) 9 return x + y; 10 if (x == y) 11 return y; 12 if (x == 0) { 13 ux.i = 1; 14 if (signbit(y)) 15 ux.i |= 0x80000000; 16 } else if (x < y) { 17 if (signbit(x)) 18 ux.i--; 19 else 20 ux.i++; 21 } else { 22 if (signbit(x)) 23 ux.i++; 24 else 25 ux.i--; 26 } 27 e = ux.i & 0x7f800000; 28 /* raise overflow if ux.f is infinite and x is finite */ 29 if (e == 0x7f800000) 30 FORCE_EVAL(x+x); 31 /* raise underflow if ux.f is subnormal or zero */ 32 if (e == 0) 33 FORCE_EVAL(x*x + ux.f*ux.f); 34 return ux.f; 35 } 36