(__ieee754_sqrt): Remove unused variables b and n.
[kopensolaris-gnu/glibc.git] / sysdeps / ieee754 / ldbl-96 / s_nexttowardf.c
1 /* s_nexttowardf.c -- float version of s_nextafter.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  */
4
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
9  * Developed at SunPro, a Sun Microsystems, Inc. business.
10  * Permission to use, copy, modify, and distribute this
11  * software is freely granted, provided that this notice
12  * is preserved.
13  * ====================================================
14  */
15
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: $";
18 #endif
19
20 #include "math.h"
21 #include "math_private.h"
22
23 #ifdef __STDC__
24         float __nexttowardf(float x, long double y)
25 #else
26         float __nexttowardf(x,y)
27         float x;
28         long double y;
29 #endif
30 {
31         int32_t hx,ix,iy;
32         u_int32_t hy,ly,esy;
33
34         GET_FLOAT_WORD(hx,x);
35         GET_LDOUBLE_WORDS(esy,hy,ly,y);
36         ix = hx&0x7fffffff;             /* |x| */
37         iy = esy&0x7fff;                /* |y| */
38
39         if((ix>0x7f800000) ||   /* x is nan */
40            (iy>=0x7fff&&((hy|ly)|-(hy|ly))!=0))     /* y is nan */
41            return x+y;
42         if((long double) x==y) return y;        /* x=y, return y */
43         if(ix==0) {                             /* x == 0 */
44             float x2;
45             SET_FLOAT_WORD(x,(esy&0x8000?0x80000000:0)|1);/* return +-minsub*/
46             x2 = x*x;
47             if(x2==x) return x2; else return x; /* raise underflow flag */
48         }
49         if(hx>=0) {                             /* x > 0 */
50             if(esy>=0x8000||((ix>>23)&0xff)>iy-0x3f80
51                || (((ix>>23)&0xff)==iy-0x3f80
52                    && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x > y, x -= ulp */
53                 hx -= 1;
54             } else {                            /* x < y, x += ulp */
55                 hx += 1;
56             }
57         } else {                                /* x < 0 */
58             if(esy<0x8000||((ix>>23)&0xff)>iy-0x3f80
59                || (((ix>>23)&0xff)==iy-0x3f80
60                    && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x < y, x -= ulp */
61                 hx -= 1;
62             } else {                            /* x > y, x += ulp */
63                 hx += 1;
64             }
65         }
66         hy = hx&0x7f800000;
67         if(hy>=0x7f800000) return x+x;  /* overflow  */
68         if(hy<0x00800000) {             /* underflow */
69             float x2 = x*x;
70             if(x2!=x) {         /* raise underflow flag */
71                 SET_FLOAT_WORD(x2,hx);
72                 return x2;
73             }
74         }
75         SET_FLOAT_WORD(x,hx);
76         return x;
77 }
78 weak_alias (__nexttowardf, nexttowardf)