1 | /* s_nextafterl.c -- long double version of s_nextafter.c. |
2 | * Special version for i387. |
3 | * Conversion to long double by Ulrich Drepper, |
4 | * Cygnus Support, drepper@cygnus.com. |
5 | */ |
6 | |
7 | /* |
8 | * ==================================================== |
9 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
10 | * |
11 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
12 | * Permission to use, copy, modify, and distribute this |
13 | * software is freely granted, provided that this notice |
14 | * is preserved. |
15 | * ==================================================== |
16 | */ |
17 | |
18 | #if defined(LIBM_SCCS) && !defined(lint) |
19 | static char rcsid[] = "$NetBSD: $" ; |
20 | #endif |
21 | |
22 | /* IEEE functions |
23 | * nextafterl(x,y) |
24 | * return the next machine floating-point number of x in the |
25 | * direction toward y. |
26 | * Special cases: |
27 | */ |
28 | |
29 | #include <errno.h> |
30 | #include <math.h> |
31 | #include <math-barriers.h> |
32 | #include <math_private.h> |
33 | #include <libm-alias-ldouble.h> |
34 | |
35 | long double __nextafterl(long double x, long double y) |
36 | { |
37 | uint32_t hx,hy,ix,iy; |
38 | uint32_t lx,ly; |
39 | int32_t esx,esy; |
40 | |
41 | GET_LDOUBLE_WORDS(esx,hx,lx,x); |
42 | GET_LDOUBLE_WORDS(esy,hy,ly,y); |
43 | ix = esx&0x7fff; /* |x| */ |
44 | iy = esy&0x7fff; /* |y| */ |
45 | |
46 | /* Intel's extended format has the normally implicit 1 explicit |
47 | present. Sigh! */ |
48 | if(((ix==0x7fff)&&(((hx&0x7fffffff)|lx)!=0)) || /* x is nan */ |
49 | ((iy==0x7fff)&&(((hy&0x7fffffff)|ly)!=0))) /* y is nan */ |
50 | return x+y; |
51 | if(x==y) return y; /* x=y, return y */ |
52 | if((ix|hx|lx)==0) { /* x == 0 */ |
53 | long double u; |
54 | SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */ |
55 | u = math_opt_barrier (x); |
56 | u = u * u; |
57 | math_force_eval (u); /* raise underflow flag */ |
58 | return x; |
59 | } |
60 | if(esx>=0) { /* x > 0 */ |
61 | if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) { |
62 | /* x > y, x -= ulp */ |
63 | if(lx==0) { |
64 | if (hx <= 0x80000000) { |
65 | if (esx == 0) { |
66 | --hx; |
67 | } else { |
68 | esx -= 1; |
69 | hx = hx - 1; |
70 | if (esx > 0) |
71 | hx |= 0x80000000; |
72 | } |
73 | } else |
74 | hx -= 1; |
75 | } |
76 | lx -= 1; |
77 | } else { /* x < y, x += ulp */ |
78 | lx += 1; |
79 | if(lx==0) { |
80 | hx += 1; |
81 | if (hx==0 || (esx == 0 && hx == 0x80000000)) { |
82 | esx += 1; |
83 | hx |= 0x80000000; |
84 | } |
85 | } |
86 | } |
87 | } else { /* x < 0 */ |
88 | if(esy>=0||(esx>esy||((esx==esy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){ |
89 | /* x < y, x -= ulp */ |
90 | if(lx==0) { |
91 | if (hx <= 0x80000000 && esx != 0xffff8000) { |
92 | esx -= 1; |
93 | hx = hx - 1; |
94 | if ((esx&0x7fff) > 0) |
95 | hx |= 0x80000000; |
96 | } else |
97 | hx -= 1; |
98 | } |
99 | lx -= 1; |
100 | } else { /* x > y, x += ulp */ |
101 | lx += 1; |
102 | if(lx==0) { |
103 | hx += 1; |
104 | if (hx==0 || (esx == 0xffff8000 && hx == 0x80000000)) { |
105 | esx += 1; |
106 | hx |= 0x80000000; |
107 | } |
108 | } |
109 | } |
110 | } |
111 | esy = esx&0x7fff; |
112 | if(esy==0x7fff) { |
113 | long double u = x + x; /* overflow */ |
114 | math_force_eval (u); |
115 | __set_errno (ERANGE); |
116 | } |
117 | if(esy==0) { |
118 | long double u = x*x; /* underflow */ |
119 | math_force_eval (u); /* raise underflow flag */ |
120 | __set_errno (ERANGE); |
121 | } |
122 | SET_LDOUBLE_WORDS(x,esx,hx,lx); |
123 | return x; |
124 | } |
125 | libm_alias_ldouble (__nextafter, nextafter) |
126 | strong_alias (__nextafterl, __nexttowardl) |
127 | weak_alias (__nextafterl, nexttowardl) |
128 | |