#define __nexttoward __internal___nexttoward
#define nexttoward __internal_nexttoward
+#include <errno.h>
#include <math.h>
-#include "math_private.h"
+#include <math-barriers.h>
+#include <math_private.h>
#include <float.h>
+#include <libm-alias-double.h>
-#ifdef __STDC__
- double __nextafter(double x, double y)
-#else
- double __nextafter(x,y)
- double x,y;
-#endif
+double __nextafter(double x, double y)
{
int32_t hx,hy,ix,iy;
- u_int32_t lx,ly;
+ uint32_t lx,ly;
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
return x+y;
if(x==y) return y; /* x=y, return y */
if((ix|lx)==0) { /* x == 0 */
+ double u;
INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
- y = x*x;
- if(y==x) return y; else return x; /* raise underflow flag */
+ u = math_opt_barrier (x);
+ u = u*u;
+ math_force_eval (u); /* raise underflow flag */
+ return x;
}
if(hx>=0) { /* x > 0 */
if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
}
hy = hx&0x7ff00000;
if(hy>=0x7ff00000) {
- x = x+x; /* overflow */
- if (FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1)
- asm ("" : "=m"(x) : "m"(x));
- return x; /* overflow */
+ double u = x+x; /* overflow */
+ math_force_eval (u);
+ __set_errno (ERANGE);
}
- if(hy<0x00100000) { /* underflow */
- y = x*x;
- if(y!=x) { /* raise underflow flag */
- INSERT_WORDS(y,hx,lx);
- return y;
- }
+ if(hy<0x00100000) {
+ double u = x*x; /* underflow */
+ math_force_eval (u); /* raise underflow flag */
+ __set_errno (ERANGE);
}
INSERT_WORDS(x,hx,lx);
return x;
}
-weak_alias (__nextafter, nextafter)
+libm_alias_double (__nextafter, nextafter)
#ifdef NO_LONG_DOUBLE
-strong_alias (__nextafter, __nextafterl)
-weak_alias (__nextafter, nextafterl)
strong_alias (__nextafter, __nexttowardl)
weak_alias (__nexttowardl, nexttowardl)
#undef __nexttoward