2.9
[glibc/nacl-glibc.git] / sysdeps / i386 / fpu / s_nexttowardf.c
blob25f70e4f4d65f49bf8648d87a6fbdc2ef94b5585
1 /* s_nexttowardf.c -- float version of s_nextafter.c.
2 * Special i387 version.
3 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
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 <float.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,iy;
34 u_int32_t hy,ly,esy;
36 GET_FLOAT_WORD(hx,x);
37 GET_LDOUBLE_WORDS(esy,hy,ly,y);
38 ix = hx&0x7fffffff; /* |x| */
39 iy = esy&0x7fff; /* |y| */
41 /* Intel's extended format has the normally implicit 1 explicit
42 present. Sigh! */
43 if((ix>0x7f800000) || /* x is nan */
44 (iy>=0x7fff&&(((hy&0x7fffffff)|ly)!=0))) /* y is nan */
45 return x+y;
46 if((long double) x==y) return y; /* x=y, return y */
47 if(ix==0) { /* x == 0 */
48 float u;
49 SET_FLOAT_WORD(x,((esy&0x8000)<<16)|1);/* return +-minsub*/
50 u = math_opt_barrier (x);
51 u = u * u;
52 math_force_eval (u); /* raise underflow flag */
53 return x;
55 if(hx>=0) { /* x > 0 */
56 if(esy>=0x8000||((ix>>23)&0xff)>iy-0x3f80
57 || (((ix>>23)&0xff)==iy-0x3f80
58 && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x > y, x -= ulp */
59 hx -= 1;
60 } else { /* x < y, x += ulp */
61 hx += 1;
63 } else { /* x < 0 */
64 if(esy<0x8000||((ix>>23)&0xff)>iy-0x3f80
65 || (((ix>>23)&0xff)==iy-0x3f80
66 && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x < y, x -= ulp */
67 hx -= 1;
68 } else { /* x > y, x += ulp */
69 hx += 1;
72 hy = hx&0x7f800000;
73 if(hy>=0x7f800000) {
74 x = x+x; /* overflow */
75 if (FLT_EVAL_METHOD != 0)
76 /* Force conversion to float. */
77 asm ("" : "+m"(x));
78 return x;
80 if(hy<0x00800000) {
81 float u = x*x; /* underflow */
82 math_force_eval (u); /* raise underflow flag */
84 SET_FLOAT_WORD(x,hx);
85 return x;
87 weak_alias (__nexttowardf, nexttowardf)