s_nextafterf.c - vx32 - Local 9vx git repository for patches.
(HTM) git clone git://r-36.net/vx32
(DIR) Log
(DIR) Files
(DIR) Refs
---
s_nextafterf.c (1708B)
---
1 /* s_nextafterf.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 #ifndef lint
17 static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafterf.c,v 1.9 2005/01/23 22:56:08 das Exp $";
18 #endif
19
20 #include "math.h"
21 #include "math_private.h"
22
23 float
24 nextafterf(float x, float y)
25 {
26 int32_t hx,hy,ix,iy;
27
28 GET_FLOAT_WORD(hx,x);
29 GET_FLOAT_WORD(hy,y);
30 ix = hx&0x7fffffff; /* |x| */
31 iy = hy&0x7fffffff; /* |y| */
32
33 if((ix>0x7f800000) || /* x is nan */
34 (iy>0x7f800000)) /* y is nan */
35 return x+y;
36 if(x==y) return y; /* x=y, return y */
37 if(ix==0) { /* x == 0 */
38 SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
39 y = x*x;
40 if(y==x) return y; else return x; /* raise underflow flag */
41 }
42 if(hx>=0) { /* x > 0 */
43 if(hx>hy) { /* x > y, x -= ulp */
44 hx -= 1;
45 } else { /* x < y, x += ulp */
46 hx += 1;
47 }
48 } else { /* x < 0 */
49 if(hy>=0||hx>hy){ /* x < y, x -= ulp */
50 hx -= 1;
51 } else { /* x > y, x += ulp */
52 hx += 1;
53 }
54 }
55 hy = hx&0x7f800000;
56 if(hy>=0x7f800000) return x+x; /* overflow */
57 if(hy<0x00800000) { /* underflow */
58 y = x*x;
59 if(y!=x) { /* raise underflow flag */
60 SET_FLOAT_WORD(y,hx);
61 return y;
62 }
63 }
64 SET_FLOAT_WORD(x,hx);
65 return x;
66 }