1 /* sf_nextafter.c -- float version of s_nextafter.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
4
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
14 */
15
16 #include "fdlibm.h"
17
nextafterf(float x,float y)18 float nextafterf(float x, float y)
19 {
20 __int32_t hx,hy,ix,iy;
21
22 GET_FLOAT_WORD(hx,x);
23 GET_FLOAT_WORD(hy,y);
24 ix = hx&0x7fffffff; /* |x| */
25 iy = hy&0x7fffffff; /* |y| */
26
27 if(FLT_UWORD_IS_NAN(ix) ||
28 FLT_UWORD_IS_NAN(iy))
29 return x+y;
30 if(x==y) return y; /* x=y, return y */
31 if(FLT_UWORD_IS_ZERO(ix)) { /* x == 0 */
32 SET_FLOAT_WORD(x,(hy&0x80000000)|FLT_UWORD_MIN);
33 force_eval_float(x*x);
34 return x;
35 }
36 if(hx>=0) { /* x > 0 */
37 if(hx>hy) { /* x > y, x -= ulp */
38 hx -= 1;
39 } else { /* x < y, x += ulp */
40 hx += 1;
41 }
42 } else { /* x < 0 */
43 if(hy>=0||hx>hy){ /* x < y, x -= ulp */
44 hx -= 1;
45 } else { /* x > y, x += ulp */
46 hx += 1;
47 }
48 }
49 hy = hx&0x7f800000;
50 if(hy>FLT_UWORD_MAX) return check_oflowf(x+x); /* overflow */
51 SET_FLOAT_WORD(x,hx);
52 if(hy<0x00800000) /* underflow */
53 return __math_denormf(x);
54 return x;
55 }
56
57 _MATH_ALIAS_f_ff(nextafter)
58