2 * Conversion from s_nextafter.c by Ulrich Drepper, Cygnus Support,
3 * drepper@cygnus.com and Jakub Jelinek, jj@ultra.linux.cz.
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
14 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
23 * return the next machine floating-point number of x in the
29 #include <math_private.h>
30 #include <math_ldbl_opt.h>
33 double __nexttoward(double x, long double y)
40 EXTRACT_WORDS(hx,lx,x);
41 GET_LDOUBLE_WORDS64(hy,ly,y);
42 ix = hx&0x7fffffff; /* |x| */
43 iy = hy&0x7fffffffffffffffLL; /* |y| */
44 uly = ly&0x7fffffffffffffffLL; /* |y| */
46 if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
47 ((iy>=0x7ff0000000000000LL)&&((iy-0x7ff0000000000000LL)|uly)!=0))
50 if((long double) x==y) return y; /* x=y, return y */
51 if((ix|lx)==0) { /* x == 0 */
53 INSERT_WORDS(x,(u_int32_t)((hy>>32)&0x80000000),1);/* return +-minsub */
54 u = math_opt_barrier (x);
56 math_force_eval (u); /* raise underflow flag */
59 if(hx>=0) { /* x > 0 */
60 if (hy<0||(ix>>20)>(iy>>52)
61 || ((ix>>20)==(iy>>52)
62 && (((((int64_t)hx)<<32)|(lx))>(hy&0x000fffffffffffffLL)
63 || (((((int64_t)hx)<<32)|(lx))==(hy&0x000fffffffffffffLL)
64 )))) { /* x > y, x -= ulp */
67 } else { /* x < y, x += ulp */
72 if (hy>=0||(ix>>20)>(iy>>52)
73 || ((ix>>20)==(iy>>52)
74 && (((((int64_t)hx)<<32)|(lx))>(hy&0x000fffffffffffffLL)
75 || (((((int64_t)hx)<<32)|(lx))==(hy&0x000fffffffffffffLL)
76 )))) { /* x < y, x -= ulp */
79 } else { /* x > y, x += ulp */
86 x = x+x; /* overflow */
87 if (FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1)
88 /* Force conversion to double. */
93 double u = x*x; /* underflow */
94 math_force_eval (u); /* raise underflow flag */
96 INSERT_WORDS(x,hx,lx);
99 long_double_symbol (libm, __nexttoward, nexttoward);