2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128 / s_nexttowardf.c
blob1a22e0102ca642f124edcf35e09d58ab0dacc67d
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 #ifdef __STDC__
25 float __nexttowardf(float x, long double y)
26 #else
27 float __nexttowardf(x,y)
28 float x;
29 long double y;
30 #endif
32 int32_t hx,ix;
33 int64_t hy,iy;
34 u_int64_t ly;
36 GET_FLOAT_WORD(hx,x);
37 GET_LDOUBLE_WORDS64(hy,ly,y);
38 ix = hx&0x7fffffff; /* |x| */
39 iy = hy&0x7fffffffffffffffLL; /* |y| */
41 if((ix>0x7f800000) || /* x is nan */
42 ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0))
43 /* y is nan */
44 return x+y;
45 if((long double) x==y) return y; /* x=y, return y */
46 if(ix==0) { /* x == 0 */
47 float x2;
48 SET_FLOAT_WORD(x,(u_int32_t)((hy>>32)&0x80000000)|1);/* return +-minsub*/
49 x2 = x*x;
50 if(x2==x) return x2; else return x; /* raise underflow flag */
52 if(hx>=0) { /* x > 0 */
53 if(hy<0||(ix>>23)>(iy>>48)-0x3f80
54 || ((ix>>23)==(iy>>48)-0x3f80
55 && (ix&0x7fffff)>((hy>>25)&0x7fffff))) {/* x > y, x -= ulp */
56 hx -= 1;
57 } else { /* x < y, x += ulp */
58 hx += 1;
60 } else { /* x < 0 */
61 if(hy>=0||(ix>>23)>(iy>>48)-0x3f80
62 || ((ix>>23)==(iy>>48)-0x3f80
63 && (ix&0x7fffff)>((hy>>25)&0x7fffff))) {/* x < y, x -= ulp */
64 hx -= 1;
65 } else { /* x > y, x += ulp */
66 hx += 1;
69 hy = hx&0x7f800000;
70 if(hy>=0x7f800000) return x+x; /* overflow */
71 if(hy<0x00800000) { /* underflow */
72 float x2 = x*x;
73 if(x2!=x) { /* raise underflow flag */
74 SET_FLOAT_WORD(x2,hx);
75 return x2;
78 SET_FLOAT_WORD(x,hx);
79 return x;
81 weak_alias (__nexttowardf, nexttowardf)