2012-03-13 01:17:53 -04:00
|
|
|
#include "libm.h"
|
|
|
|
|
|
|
|
float nexttowardf(float x, long double y)
|
|
|
|
{
|
2012-05-06 13:08:59 +02:00
|
|
|
union fshape ux;
|
|
|
|
uint32_t e;
|
2012-03-13 01:17:53 -04:00
|
|
|
|
2012-05-06 13:08:59 +02:00
|
|
|
if (isnan(x) || isnan(y))
|
|
|
|
return x + y;
|
2012-03-13 01:17:53 -04:00
|
|
|
if (x == y)
|
2012-05-06 13:08:59 +02:00
|
|
|
return y;
|
|
|
|
ux.value = x;
|
|
|
|
if (x == 0) {
|
|
|
|
ux.bits = 1;
|
|
|
|
if (signbit(y))
|
|
|
|
ux.bits |= 0x80000000;
|
|
|
|
} else if (x < y) {
|
|
|
|
if (signbit(x))
|
|
|
|
ux.bits--;
|
|
|
|
else
|
|
|
|
ux.bits++;
|
|
|
|
} else {
|
|
|
|
if (signbit(x))
|
|
|
|
ux.bits++;
|
|
|
|
else
|
|
|
|
ux.bits--;
|
2012-03-13 01:17:53 -04:00
|
|
|
}
|
2012-05-06 13:08:59 +02:00
|
|
|
e = ux.bits & 0x7f800000;
|
|
|
|
/* raise overflow if ux.value is infinite and x is finite */
|
|
|
|
if (e == 0x7f800000)
|
|
|
|
return x + x;
|
|
|
|
/* raise underflow if ux.value is subnormal or zero */
|
2012-05-06 21:24:28 +02:00
|
|
|
if (e == 0)
|
|
|
|
FORCE_EVAL(x*x + ux.value*ux.value);
|
2012-05-06 13:08:59 +02:00
|
|
|
return ux.value;
|
2012-03-13 01:17:53 -04:00
|
|
|
}
|