1 /* @(#)s_nextafter.c 5.1 93/09/24 */
2 /*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 *
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
9 * is preserved.
10 * ====================================================
11 */
12
13 /* IEEE functions
14 * nextafterl(x,y)
15 * return the next machine floating-point number of x in the
16 * direction toward y.
17 * Special cases:
18 */
19
20
21
22 long double
nextafterl(long double x,long double y)23 nextafterl(long double x, long double y)
24 {
25 int64_t hx,hy,ix,iy;
26 u_int64_t lx,ly;
27
28 GET_LDOUBLE_WORDS64(hx,lx,x);
29 GET_LDOUBLE_WORDS64(hy,ly,y);
30 ix = hx&0x7fffffffffffffffLL; /* |x| */
31 iy = hy&0x7fffffffffffffffLL; /* |y| */
32
33 if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) || /* x is nan */
34 ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0)) /* y is nan */
35 return x+y;
36 if(x==y) return y; /* x=y, return y */
37 if((ix|lx)==0) { /* x == 0 */
38 SET_LDOUBLE_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */
39 force_eval_long_double(x*x);
40 return x;
41 }
42 if(hx>=0) { /* x > 0 */
43 if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
44 if(lx==0) hx--;
45 lx--;
46 } else { /* x < y, x += ulp */
47 lx++;
48 if(lx==0) hx++;
49 }
50 } else { /* x < 0 */
51 if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
52 if(lx==0) hx--;
53 lx--;
54 } else { /* x > y, x += ulp */
55 lx++;
56 if(lx==0) hx++;
57 }
58 }
59 ix = hx&0x7fff000000000000LL;
60 if(ix==0x7fff000000000000LL)
61 return __math_oflowl(hy<0);
62 SET_LDOUBLE_WORDS64(x,hx,lx);
63 if(ix==0)
64 return __math_denorml(x);
65 return x;
66 }
67
68 #ifdef _HAVE_ALIAS_ATTRIBUTE
69 __strong_reference(nextafterl, nexttowardl);
70 #else
71 long double
nexttowardl(long double x,long double y)72 nexttowardl(long double x, long double y)
73 {
74 return nextafterl(x, y);
75 }
76 #endif
77