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