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