Update.
[glibc.git] / sysdeps / libm-ieee754 / s_nextafterxf.c
blob7e870805e2940eab1dfa68bd1a39747a3030174e
1 /* s_nextafterxf.c -- float version of s_nextafter.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: $";
18 #endif
20 #include "math.h"
21 #include "math_private.h"
23 #ifdef __STDC__
24 float __nextafterxf(float x, long double y)
25 #else
26 float __nextafterxf(x,y)
27 float x;
28 log double y;
29 #endif
31 int32_t hx,ix,iy;
32 u_int32_t hy,ly,esy;
34 GET_FLOAT_WORD(hx,x);
35 GET_LDOUBLE_WORDS(esy,hy,ly,y);
36 ix = hx&0x7fffffff; /* |x| */
37 iy = esy&0x7fff; /* |y| */
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 */
49 if(hx>=0) { /* x > 0 */
50 if(esy>=0x8000||((ix>>23)&0xff)>iy
51 || (((ix>>23)&0xff)==iy
52 && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x > y, x -= ulp */
53 hx -= 1;
54 } else { /* x < y, x += ulp */
55 hx += 1;
57 } else { /* x < 0 */
58 if(esy<0x8000||((ix>>23)&0xff)>iy
59 || (((ix>>23)&0xff)==iy
60 && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x < y, x -= ulp */
61 hx -= 1;
62 } else { /* x > y, x += ulp */
63 hx += 1;
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;
75 SET_FLOAT_WORD(x,hx);
76 return x;
78 weak_alias (__nextafterxf, nextafterxf)