[BZ #2510, BZ #2830, BZ #3137, BZ #3313, BZ #3426, BZ #3465, BZ #3480, BZ #3483,...
[glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_nexttowardf.c
bloba9373ff822162becd1cc591e9afa7fc8c01a1438
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>
25 #ifdef __STDC__
26 float __nexttowardf(float x, long double y)
27 #else
28 float __nexttowardf(x,y)
29 float x;
30 long double y;
31 #endif
33 int32_t hx,ix;
34 int64_t hy,iy;
35 u_int64_t ly, uly;
37 GET_FLOAT_WORD(hx,x);
38 GET_LDOUBLE_WORDS64(hy,ly,y);
39 ix = hx&0x7fffffff; /* |x| */
40 iy = hy&0x7fffffffffffffffLL; /* |y| */
41 uly = ly&0x7fffffffffffffffLL; /* |y| */
43 if((ix>0x7f800000) || /* x is nan */
44 ((iy>=0x7ff0000000000000LL)&&((iy-0x7ff0000000000000LL)|uly)!=0))
45 /* y is nan */
46 return x+y;
47 if((long double) x==y) return y; /* x=y, return y */
48 if(ix==0) { /* x == 0 */
49 float x2;
50 SET_FLOAT_WORD(x,(u_int32_t)((hy>>32)&0x80000000)|1);/* return +-minsub*/
51 x2 = x*x;
52 if(x2==x) return x2; else return x; /* raise underflow flag */
54 if(hx>=0) { /* x > 0 */
55 if(hy<0||(ix>>23)>(iy>>52)-0x380
56 || ((ix>>23)==(iy>>52)-0x380
57 && (ix&0x7fffff)>((hy>>29)&0x7fffff))) {/* x > y, x -= ulp */
58 hx -= 1;
59 } else { /* x < y, x += ulp */
60 hx += 1;
62 } else { /* x < 0 */
63 if(hy>=0||(ix>>23)>(iy>>52)-0x380
64 || ((ix>>23)==(iy>>52)-0x380
65 && (ix&0x7fffff)>((hy>>29)&0x7fffff))) {/* x < y, x -= ulp */
66 hx -= 1;
67 } else { /* x > y, x += ulp */
68 hx += 1;
71 hy = hx&0x7f800000;
72 if(hy>=0x7f800000) return x+x; /* overflow */
73 if(hy<0x00800000) { /* underflow */
74 float x2 = x*x;
75 if(x2!=x) { /* raise underflow flag */
76 SET_FLOAT_WORD(x2,hx);
77 return x2;
80 SET_FLOAT_WORD(x,hx);
81 return x;
83 long_double_symbol (libm, __nexttowardf, nexttowardf);