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 | */ |
4 | |
5 | /* |
6 | * ==================================================== |
7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
8 | * |
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 | * ==================================================== |
14 | */ |
15 | |
16 | #if defined(LIBM_SCCS) && !defined(lint) |
17 | static char rcsid[] = "$NetBSD: $" ; |
18 | #endif |
19 | |
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: |
25 | */ |
26 | |
27 | #include <errno.h> |
28 | #include <math.h> |
29 | #include <math-barriers.h> |
30 | #include <math_private.h> |
31 | #include <libm-alias-ldouble.h> |
32 | |
33 | _Float128 __nextafterl(_Float128 x, _Float128 y) |
34 | { |
35 | int64_t hx,hy,ix,iy; |
36 | uint64_t lx,ly; |
37 | |
38 | GET_LDOUBLE_WORDS64(hx,lx,x); |
39 | GET_LDOUBLE_WORDS64(hy,ly,y); |
40 | ix = hx&0x7fffffffffffffffLL; /* |x| */ |
41 | iy = hy&0x7fffffffffffffffLL; /* |y| */ |
42 | |
43 | if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) || /* x is nan */ |
44 | ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0)) /* y is nan */ |
45 | return x+y; |
46 | if(x==y) return y; /* x=y, return y */ |
47 | if((ix|lx)==0) { /* x == 0 */ |
48 | _Float128 u; |
49 | SET_LDOUBLE_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */ |
50 | u = math_opt_barrier (x); |
51 | u = u * u; |
52 | math_force_eval (u); /* raise underflow flag */ |
53 | return x; |
54 | } |
55 | if(hx>=0) { /* x > 0 */ |
56 | if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ |
57 | if(lx==0) hx--; |
58 | lx--; |
59 | } else { /* x < y, x += ulp */ |
60 | lx++; |
61 | if(lx==0) hx++; |
62 | } |
63 | } else { /* x < 0 */ |
64 | if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */ |
65 | if(lx==0) hx--; |
66 | lx--; |
67 | } else { /* x > y, x += ulp */ |
68 | lx++; |
69 | if(lx==0) hx++; |
70 | } |
71 | } |
72 | hy = hx&0x7fff000000000000LL; |
73 | if(hy==0x7fff000000000000LL) { |
74 | _Float128 u = x + x; /* overflow */ |
75 | math_force_eval (u); |
76 | __set_errno (ERANGE); |
77 | } |
78 | if(hy==0) { |
79 | _Float128 u = x*x; /* underflow */ |
80 | math_force_eval (u); /* raise underflow flag */ |
81 | __set_errno (ERANGE); |
82 | } |
83 | SET_LDOUBLE_WORDS64(x,hx,lx); |
84 | return x; |
85 | } |
86 | libm_alias_ldouble (__nextafter, nextafter) |
87 | strong_alias (__nextafterl, __nexttowardl) |
88 | weak_alias (__nextafterl, nexttowardl) |
89 | |