#include <sys/cdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: s_nextafter.c,v 1.10 1999/07/02 15:37:43 simonb Exp $");
#endif
#include "math.h"
#include "math_private.h"
static 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) {
if (( x == 0.0 ) && ( y == 0.0 )) return y;
else
return x;
}
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;
}
#if !defined(BUILDING_FOR_CARBONCORE_LEGACY)
double nextafter(double x, double y)
{
return __nextafter( x, y );
}
#else
double nextafterd(double x, double y)
{
return __nextafter( x, y );
}
#endif