Fix Wundef warning for __STDC_VERSION__
[glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_nexttowardf.c
blob19522f4762f6a75b01fb3d6d35ff3992fc76ca81
1 /* s_nexttowardf.c -- float version of s_nextafter.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com
3 * and Jakub Jelinek, jj@ultra.linux.cz.
4 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
21 #include <math.h>
22 #include <math_private.h>
23 #include <math_ldbl_opt.h>
24 #include <float.h>
26 float __nexttowardf(float x, long double y)
28 int32_t hx,ix;
29 int64_t hy,iy;
30 double yhi;
32 GET_FLOAT_WORD(hx,x);
33 yhi = ldbl_high (y);
34 EXTRACT_WORDS64 (hy, yhi);
35 ix = hx&0x7fffffff; /* |x| */
36 iy = hy&0x7fffffffffffffffLL; /* |y| */
38 if((ix>0x7f800000) || /* x is nan */
39 (iy>0x7ff0000000000000LL))
40 /* 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 u;
45 SET_FLOAT_WORD(x,(u_int32_t)((hy>>32)&0x80000000)|1);/* return +-minsub*/
46 u = math_opt_barrier (x);
47 u = u * u;
48 math_force_eval (u); /* raise underflow flag */
49 return x;
51 if(hx>=0) { /* x > 0 */
52 if(x > y) { /* x -= ulp */
53 hx -= 1;
54 } else { /* x < y, x += ulp */
55 hx += 1;
57 } else { /* x < 0 */
58 if(x < y) { /* x -= ulp */
59 hx -= 1;
60 } else { /* x > y, x += ulp */
61 hx += 1;
64 hy = hx&0x7f800000;
65 if(hy>=0x7f800000) {
66 x = x+x; /* overflow */
67 if (FLT_EVAL_METHOD != 0)
68 /* Force conversion to float. */
69 asm ("" : "+m"(x));
70 return x;
72 if(hy<0x00800000) { /* underflow */
73 float u = x*x;
74 math_force_eval (u); /* raise underflow flag */
76 SET_FLOAT_WORD(x,hx);
77 return x;
79 long_double_symbol (libm, __nexttowardf, nexttowardf);