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_private.h> |
32 | |
33 | long double __nextafterl(long double x, long double y) |
34 | { |
35 | u_int32_t hx,hy,ix,iy; |
36 | u_int32_t lx,ly; |
37 | int32_t esx,esy; |
38 | |
39 | GET_LDOUBLE_WORDS(esx,hx,lx,x); |
40 | GET_LDOUBLE_WORDS(esy,hy,ly,y); |
41 | ix = esx&0x7fff; /* |x| */ |
42 | iy = esy&0x7fff; /* |y| */ |
43 | |
44 | /* Intel's extended format has the normally implicit 1 explicit |
45 | present. Sigh! */ |
46 | if(((ix==0x7fff)&&(((hx&0x7fffffff)|lx)!=0)) || /* x is nan */ |
47 | ((iy==0x7fff)&&(((hy&0x7fffffff)|ly)!=0))) /* y is nan */ |
48 | return x+y; |
49 | if(x==y) return y; /* x=y, return y */ |
50 | if((ix|hx|lx)==0) { /* x == 0 */ |
51 | long double u; |
52 | SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */ |
53 | u = math_opt_barrier (x); |
54 | u = u * u; |
55 | math_force_eval (u); /* raise underflow flag */ |
56 | return x; |
57 | } |
58 | if(esx>=0) { /* x > 0 */ |
59 | if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) { |
60 | /* x > y, x -= ulp */ |
61 | if(lx==0) { |
62 | if (hx <= 0x80000000) { |
63 | if (esx == 0) { |
64 | --hx; |
65 | } else { |
66 | esx -= 1; |
67 | hx = hx - 1; |
68 | if (esx > 0) |
69 | hx |= 0x80000000; |
70 | } |
71 | } else |
72 | hx -= 1; |
73 | } |
74 | lx -= 1; |
75 | } else { /* x < y, x += ulp */ |
76 | lx += 1; |
77 | if(lx==0) { |
78 | hx += 1; |
79 | if (hx==0 || (esx == 0 && hx == 0x80000000)) { |
80 | esx += 1; |
81 | hx |= 0x80000000; |
82 | } |
83 | } |
84 | } |
85 | } else { /* x < 0 */ |
86 | if(esy>=0||(esx>esy||((esx==esy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){ |
87 | /* x < y, x -= ulp */ |
88 | if(lx==0) { |
89 | if (hx <= 0x80000000 && esx != 0xffff8000) { |
90 | esx -= 1; |
91 | hx = hx - 1; |
92 | if ((esx&0x7fff) > 0) |
93 | hx |= 0x80000000; |
94 | } else |
95 | hx -= 1; |
96 | } |
97 | lx -= 1; |
98 | } else { /* x > y, x += ulp */ |
99 | lx += 1; |
100 | if(lx==0) { |
101 | hx += 1; |
102 | if (hx==0 || (esx == 0xffff8000 && hx == 0x80000000)) { |
103 | esx += 1; |
104 | hx |= 0x80000000; |
105 | } |
106 | } |
107 | } |
108 | } |
109 | esy = esx&0x7fff; |
110 | if(esy==0x7fff) { |
111 | long double u = x + x; /* overflow */ |
112 | math_force_eval (u); |
113 | __set_errno (ERANGE); |
114 | } |
115 | if(esy==0) { |
116 | long double u = x*x; /* underflow */ |
117 | math_force_eval (u); /* raise underflow flag */ |
118 | __set_errno (ERANGE); |
119 | } |
120 | SET_LDOUBLE_WORDS(x,esx,hx,lx); |
121 | return x; |
122 | } |
123 | weak_alias (__nextafterl, nextafterl) |
124 | strong_alias (__nextafterl, __nexttowardl) |
125 | weak_alias (__nextafterl, nexttowardl) |
126 | |