#include <float.h>
#include "fpmath.h"
#include "math.h"
#include "math_private.h"
#define LDBL_INFNAN_EXP (LDBL_MAX_EXP * 2 - 1)
float
nexttowardf(float x, long double y)
{
union IEEEl2bits uy;
volatile float t;
int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
uy.e = y;
if((ix>0x7f800000) ||
(uy.bits.exp == LDBL_INFNAN_EXP &&
((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
return x+y;
if(x==y) return (float)y;
if(ix==0) {
SET_FLOAT_WORD(x,(uy.bits.sign<<31)|1);
t = x*x;
if(t==x) return t; else return x;
}
if(hx>=0 ^ x < y)
hx -= 1;
else
hx += 1;
ix = hx&0x7f800000;
if(ix>=0x7f800000) return x+x;
if(ix<0x00800000) {
t = x*x;
if(t!=x) {
SET_FLOAT_WORD(x,hx);
return x;
}
}
SET_FLOAT_WORD(x,hx);
return x;
}