Rev 1618 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 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[] = "$\Id: s_nextafterf.c,v 1.2 1995/05/30 05:50:13 rgrimes Exp $"; |
||
18 | #endif |
||
19 | |||
20 | #include "math.h" |
||
21 | #include "math_private.h" |
||
22 | |||
23 | #ifdef __STDC__ |
||
24 | float nextafterf(float x, float y) |
||
25 | #else |
||
26 | float nextafterf(x,y) |
||
27 | float x,y; |
||
28 | #endif |
||
29 | { |
||
30 | int32_t hx,hy,ix,iy; |
||
31 | |||
32 | GET_FLOAT_WORD(hx,x); |
||
33 | GET_FLOAT_WORD(hy,y); |
||
34 | ix = hx&0x7fffffff; /* |x| */ |
||
35 | iy = hy&0x7fffffff; /* |y| */ |
||
36 | |||
37 | if((ix>0x7f800000) || /* x is nan */ |
||
38 | (iy>0x7f800000)) /* y is nan */ |
||
39 | return x+y; |
||
40 | if(x==y) return x; /* x=y, return x */ |
||
41 | if(ix==0) { /* x == 0 */ |
||
42 | SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */ |
||
43 | y = x*x; |
||
44 | if(y==x) return y; else return x; /* raise underflow flag */ |
||
45 | } |
||
46 | if(hx>=0) { /* x > 0 */ |
||
47 | if(hx>hy) { /* x > y, x -= ulp */ |
||
48 | hx -= 1; |
||
49 | } else { /* x < y, x += ulp */ |
||
50 | hx += 1; |
||
51 | } |
||
52 | } else { /* x < 0 */ |
||
53 | if(hy>=0||hx>hy){ /* x < y, x -= ulp */ |
||
54 | hx -= 1; |
||
55 | } else { /* x > y, x += ulp */ |
||
56 | hx += 1; |
||
57 | } |
||
58 | } |
||
59 | hy = hx&0x7f800000; |
||
60 | if(hy>=0x7f800000) return x+x; /* overflow */ |
||
61 | if(hy<0x00800000) { /* underflow */ |
||
62 | y = x*x; |
||
63 | if(y!=x) { /* raise underflow flag */ |
||
64 | SET_FLOAT_WORD(y,hx); |
||
65 | return y; |
||
66 | } |
||
67 | } |
||
68 | SET_FLOAT_WORD(x,hx); |
||
69 | return x; |
||
70 | } |