1 /* @(#)s_nextafter.c 5.1 93/09/24 */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
15 * return the next machine floating-point number of x in the
23 #include "math_private.h"
26 nexttoward(double x, long double y)
29 u_int32_t lx,hy,ly,esy;
31 EXTRACT_WORDS(hx,lx,x);
32 GET_LDOUBLE_WORDS(esy,hy,ly,y);
33 ix = hx&0x7fffffff; /* |x| */
34 iy = esy&0x7fff; /* |y| */
36 if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
37 ((iy>=0x7fff)&&(hy|ly)!=0)) /* y is nan */
39 if((long double) x==y) return y; /* x=y, return y */
40 if((ix|lx)==0) { /* x == 0 */
42 INSERT_WORDS(x,(esy&0x8000)<<16,1); /* return +-minsub */
44 u = u * u; /* raise underflow flag */
47 if(hx>=0) { /* x > 0 */
48 if (esy>=0x8000||((ix>>20)&0x7ff)>iy-0x3c00
49 || (((ix>>20)&0x7ff)==iy-0x3c00
50 && (((hx<<11)|(lx>>21))>(hy&0x7fffffff)
51 || (((hx<<11)|(lx>>21))==(hy&0x7fffffff)
52 && (lx<<11)>ly)))) { /* x > y, x -= ulp */
55 } else { /* x < y, x += ulp */
60 if (esy<0x8000||((ix>>20)&0x7ff)>iy-0x3c00
61 || (((ix>>20)&0x7ff)==iy-0x3c00
62 && (((hx<<11)|(lx>>21))>(hy&0x7fffffff)
63 || (((hx<<11)|(lx>>21))==(hy&0x7fffffff)
64 && (lx<<11)>ly)))) {/* x < y, x -= ulp */
67 } else { /* x > y, x += ulp */
74 x = x+x; /* overflow */
78 volatile double u = x*x; /* underflow */
80 INSERT_WORDS(x,hx,lx);
84 INSERT_WORDS(x,hx,lx);