#include <float.h>
#include <math.h>
#include "math_private.h"
double
nextafter(double x, double y)
{
int32_t hx,hy,ix,iy;
u_int32_t lx,ly;
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
ix = hx&0x7fffffff;
iy = hy&0x7fffffff;
if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) ||
((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0))
return x+y;
if(x==y) return y;
if((ix|lx)==0) {
INSERT_WORDS(x,hy&0x80000000,1);
y = x*x;
if(y==x) return y; else return x;
}
if(hx>=0) {
if(hx>hy||((hx==hy)&&(lx>ly))) {
if(lx==0) hx -= 1;
lx -= 1;
} else {
lx += 1;
if(lx==0) hx += 1;
}
} else {
if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){
if(lx==0) hx -= 1;
lx -= 1;
} else {
lx += 1;
if(lx==0) hx += 1;
}
}
hy = hx&0x7ff00000;
if(hy>=0x7ff00000) return x+x;
if(hy<0x00100000) {
y = x*x;
if(y!=x) {
INSERT_WORDS(y,hx,lx);
return y;
}
}
INSERT_WORDS(x,hx,lx);
return x;
}
DEF_STD(nextafter);
LDBL_MAYBE_CLONE(nextafter);
#if LDBL_MANT_DIG == DBL_MANT_DIG
MAKE_UNUSED_CLONE(nexttoward, nextafter);
MAKE_UNUSED_CLONE(nexttowardl, nextafter);
#endif