Unify wint_t handling in wchar.h and wctype.h.
[glibc.git] / sysdeps / ieee754 / ldbl-opt / s_nexttowardfd.c
blob68027f26fa3c36660b0356b54b766d51002cbf2a
1 /* Single precision version of nexttoward.c.
2 Conversion to IEEE single float by Jakub Jelinek, jj@ultra.linux.cz. */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
14 /* IEEE functions
15 * __nexttowardfd(x,y)
16 * return the next machine floating-point number of x in the
17 * direction toward y.
18 * This is for machines which use different binary type for double and
19 * long double conditionally, y is long double equal to double.
20 * Special cases:
23 #include <math.h>
24 #include <math_private.h>
25 #include <math_ldbl_opt.h>
26 #include <float.h>
28 float __nldbl_nexttowardf(float x, double y);
30 float __nldbl_nexttowardf(float x, double y)
32 int32_t hx,hy,ix,iy;
33 u_int32_t ly;
35 GET_FLOAT_WORD(hx,x);
36 EXTRACT_WORDS(hy,ly,y);
37 ix = hx&0x7fffffff; /* |x| */
38 iy = hy&0x7fffffff; /* |y| */
40 if((ix>0x7f800000) || /* x is nan */
41 ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
42 return x+y;
43 if((double) x==y) return y; /* x=y, return y */
44 if(ix==0) { /* x == 0 */
45 float u;
46 SET_FLOAT_WORD(x,(u_int32_t)(hy&0x80000000)|1);/* return +-minsub*/
47 u = math_opt_barrier (x);
48 u = u * u;
49 math_force_eval (u); /* raise underflow flag */
50 return x;
52 if(hx>=0) { /* x > 0 */
53 if(hy<0||(ix>>23)>(iy>>20)-0x380
54 || ((ix>>23)==(iy>>20)-0x380
55 && (ix&0x7fffff)>(((hy<<3)|(ly>>29))&0x7fffff))) /* x > y, x -= ulp */
56 hx -= 1;
57 else /* x < y, x += ulp */
58 hx += 1;
59 } else { /* x < 0 */
60 if(hy>=0||(ix>>23)>(iy>>20)-0x380
61 || ((ix>>23)==(iy>>20)-0x380
62 && (ix&0x7fffff)>(((hy<<3)|(ly>>29))&0x7fffff))) /* x < y, x -= ulp */
63 hx -= 1;
64 else /* x > y, x += ulp */
65 hx += 1;
67 hy = hx&0x7f800000;
68 if(hy>=0x7f800000) {
69 x = x+x; /* overflow */
70 if (FLT_EVAL_METHOD != 0)
71 /* Force conversion to float. */
72 asm ("" : "+m"(x));
73 return x;
75 if(hy<0x00800000) {
76 float u = x*x; /* underflow */
77 math_force_eval (u); /* raise underflow flag */
79 SET_FLOAT_WORD(x,hx);
80 return x;
83 #if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1)
84 compat_symbol (libm, __nldbl_nexttowardf, nexttowardf, GLIBC_2_1);
85 #endif