Fix ldbl-128 expm1l (-min_subnorm) result sign (bug 18619).
[glibc.git] / sysdeps / ieee754 / ldbl-128 / s_nexttowardf.c
blobccd49d235d33dc9b22c8aa43dbb48abececd4d75
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>
24 float __nexttowardf(float x, long double y)
26 int32_t hx,ix;
27 int64_t hy,iy;
28 u_int64_t ly;
30 GET_FLOAT_WORD(hx,x);
31 GET_LDOUBLE_WORDS64(hy,ly,y);
32 ix = hx&0x7fffffff; /* |x| */
33 iy = hy&0x7fffffffffffffffLL; /* |y| */
35 if((ix>0x7f800000) || /* x is nan */
36 ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0))
37 /* y is nan */
38 return x+y;
39 if((long double) x==y) return y; /* x=y, return y */
40 if(ix==0) { /* x == 0 */
41 float u;
42 SET_FLOAT_WORD(x,(u_int32_t)((hy>>32)&0x80000000)|1);/* return +-minsub*/
43 u = math_opt_barrier (x);
44 u = u * u;
45 math_force_eval (u); /* raise underflow flag */
46 return x;
48 if(hx>=0) { /* x > 0 */
49 if(x > y) { /* x -= ulp */
50 hx -= 1;
51 } else { /* x < y, x += ulp */
52 hx += 1;
54 } else { /* x < 0 */
55 if(x < y) { /* x < y, x -= ulp */
56 hx -= 1;
57 } else { /* x > y, x += ulp */
58 hx += 1;
61 hy = hx&0x7f800000;
62 if(hy>=0x7f800000) return x+x; /* overflow */
63 if(hy<0x00800000) {
64 float u = x*x; /* underflow */
65 math_force_eval (u); /* raise underflow flag */
67 SET_FLOAT_WORD(x,hx);
68 return x;
70 weak_alias (__nexttowardf, nexttowardf)