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 |
|
|
#include "math.h" |
17 |
|
|
#include "math_private.h" |
18 |
|
|
|
19 |
|
|
float |
20 |
|
|
nextafterf(float x, float y) |
21 |
|
|
{ |
22 |
|
|
int32_t hx,hy,ix,iy; |
23 |
|
|
|
24 |
|
54 |
GET_FLOAT_WORD(hx,x); |
25 |
|
27 |
GET_FLOAT_WORD(hy,y); |
26 |
|
27 |
ix = hx&0x7fffffff; /* |x| */ |
27 |
|
27 |
iy = hy&0x7fffffff; /* |y| */ |
28 |
|
|
|
29 |
✓✓ |
54 |
if((ix>0x7f800000) || /* x is nan */ |
30 |
|
27 |
(iy>0x7f800000)) /* y is nan */ |
31 |
|
9 |
return x+y; |
32 |
✓✓ |
30 |
if(x==y) return y; /* x=y, return y */ |
33 |
✗✓ |
6 |
if(ix==0) { /* x == 0 */ |
34 |
|
|
SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */ |
35 |
|
|
y = x*x; |
36 |
|
|
if(y==x) return y; else return x; /* raise underflow flag */ |
37 |
|
|
} |
38 |
✓✗ |
6 |
if(hx>=0) { /* x > 0 */ |
39 |
✓✓ |
6 |
if(hx>hy) { /* x > y, x -= ulp */ |
40 |
|
3 |
hx -= 1; |
41 |
|
3 |
} else { /* x < y, x += ulp */ |
42 |
|
3 |
hx += 1; |
43 |
|
|
} |
44 |
|
|
} else { /* x < 0 */ |
45 |
|
|
if(hy>=0||hx>hy){ /* x < y, x -= ulp */ |
46 |
|
|
hx -= 1; |
47 |
|
|
} else { /* x > y, x += ulp */ |
48 |
|
|
hx += 1; |
49 |
|
|
} |
50 |
|
|
} |
51 |
|
6 |
hy = hx&0x7f800000; |
52 |
✗✓ |
6 |
if(hy>=0x7f800000) return x+x; /* overflow */ |
53 |
✗✓ |
6 |
if(hy<0x00800000) { /* underflow */ |
54 |
|
|
y = x*x; |
55 |
|
|
if(y!=x) { /* raise underflow flag */ |
56 |
|
|
SET_FLOAT_WORD(y,hx); |
57 |
|
|
return y; |
58 |
|
|
} |
59 |
|
|
} |
60 |
|
6 |
SET_FLOAT_WORD(x,hx); |
61 |
|
6 |
return x; |
62 |
|
27 |
} |