2.9
[glibc/nacl-glibc.git] / sysdeps / i386 / fpu / s_nextafterl.c
blobaef0a144e5331e8b4b95bc2be4331dfe4611efc1
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 */
7 /*
8 * ====================================================
9 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
18 #if defined(LIBM_SCCS) && !defined(lint)
19 static char rcsid[] = "$NetBSD: $";
20 #endif
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:
29 #include "math.h"
30 #include <math_private.h>
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
39 u_int32_t hx,hy,ix,iy;
40 u_int32_t lx,ly;
41 int32_t esx,esy;
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| */
48 /* Intel's extended format has the normally implicit 1 explicit
49 present. Sigh! */
50 if(((ix==0x7fff)&&(((hx&0x7fffffff)|lx)!=0)) || /* x is nan */
51 ((iy==0x7fff)&&(((hy&0x7fffffff)|ly)!=0))) /* y is nan */
52 return x+y;
53 if(x==y) return y; /* x=y, return y */
54 if((ix|hx|lx)==0) { /* x == 0 */
55 long double u;
56 SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */
57 u = math_opt_barrier (x);
58 u = u * u;
59 math_force_eval (u); /* raise underflow flag */
60 return x;
62 if(esx>=0) { /* x > 0 */
63 if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) {
64 /* x > y, x -= ulp */
65 if(lx==0) {
66 if (hx <= 0x80000000) {
67 if (esx == 0) {
68 --hx;
69 } else {
70 esx -= 1;
71 hx = hx - 1;
72 if (esx > 0)
73 hx |= 0x80000000;
75 } else
76 hx -= 1;
78 lx -= 1;
79 } else { /* x < y, x += ulp */
80 lx += 1;
81 if(lx==0) {
82 hx += 1;
83 if (hx==0 || (esx == 0 && hx == 0x80000000)) {
84 esx += 1;
85 hx |= 0x80000000;
89 } else { /* x < 0 */
90 if(esy>=0||(esx>esy||((esx==esy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){
91 /* x < y, x -= ulp */
92 if(lx==0) {
93 if (hx <= 0x80000000) {
94 esx -= 1;
95 hx = hx - 1;
96 if ((esx&0x7fff) > 0)
97 hx |= 0x80000000;
98 } else
99 hx -= 1;
101 lx -= 1;
102 } else { /* x > y, x += ulp */
103 lx += 1;
104 if(lx==0) {
105 hx += 1;
106 if (hx==0 || (esx == 0xffff8000 && hx == 0x80000000)) {
107 esx += 1;
108 hx |= 0x80000000;
113 esy = esx&0x7fff;
114 if(esy==0x7fff) return x+x; /* overflow */
115 if(esy==0) {
116 long double u = x*x; /* underflow */
117 math_force_eval (u); /* raise underflow flag */
119 SET_LDOUBLE_WORDS(x,esx,hx,lx);
120 return x;
122 weak_alias (__nextafterl, nextafterl)
123 strong_alias (__nextafterl, __nexttowardl)
124 weak_alias (__nextafterl, nexttowardl)