1 /* s_nextafterl.c -- long double version of s_nextafter.c.
2 */
3
4 /*
5 * ====================================================
6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 *
8 * Developed at SunPro, a Sun Microsystems, Inc. business.
9 * Permission to use, copy, modify, and distribute this
10 * software is freely granted, provided that this notice
11 * is preserved.
12 * ====================================================
13 */
14
15 #if defined(LIBM_SCCS) && !defined(lint)
16 static char rcsid[] = "$NetBSD: $";
17 #endif
18
19 /* IEEE functions
20 * nextafterl(x,y)
21 * return the next machine floating-point number of x in the
22 * direction toward y.
23 * Special cases:
24 */
25
26 #include <errno.h>
27 #include <math.h>
28 #include <math-barriers.h>
29 #include <math_private.h>
30 #include <libm-alias-ldouble.h>
31
__nextafterl(_Float128 x,_Float128 y)32 _Float128 __nextafterl(_Float128 x, _Float128 y)
33 {
34 int64_t hx,hy,ix,iy;
35 uint64_t lx,ly;
36
37 GET_LDOUBLE_WORDS64(hx,lx,x);
38 GET_LDOUBLE_WORDS64(hy,ly,y);
39 ix = hx&0x7fffffffffffffffLL; /* |x| */
40 iy = hy&0x7fffffffffffffffLL; /* |y| */
41
42 if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) || /* x is nan */
43 ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0)) /* y is nan */
44 return x+y;
45 if(x==y) return y; /* x=y, return y */
46 if((ix|lx)==0) { /* x == 0 */
47 _Float128 u;
48 SET_LDOUBLE_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */
49 u = math_opt_barrier (x);
50 u = u * u;
51 math_force_eval (u); /* raise underflow flag */
52 return x;
53 }
54 if(hx>=0) { /* x > 0 */
55 if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
56 if(lx==0) hx--;
57 lx--;
58 } else { /* x < y, x += ulp */
59 lx++;
60 if(lx==0) hx++;
61 }
62 } else { /* x < 0 */
63 if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
64 if(lx==0) hx--;
65 lx--;
66 } else { /* x > y, x += ulp */
67 lx++;
68 if(lx==0) hx++;
69 }
70 }
71 hy = hx&0x7fff000000000000LL;
72 if(hy==0x7fff000000000000LL) {
73 _Float128 u = x + x; /* overflow */
74 math_force_eval (u);
75 __set_errno (ERANGE);
76 }
77 if(hy==0) {
78 _Float128 u = x*x; /* underflow */
79 math_force_eval (u); /* raise underflow flag */
80 __set_errno (ERANGE);
81 }
82 SET_LDOUBLE_WORDS64(x,hx,lx);
83 return x;
84 }
85 libm_alias_ldouble (__nextafter, nextafter)
86 strong_alias (__nextafterl, __nexttowardl)
87 weak_alias (__nextafterl, nexttowardl)
88