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