branch update for HEAD-2003091401
[reactos.git] / lib / crtdll / float / nextaf.c
1 #define MAX_DOUBLE 1.7976931348623158e+308
2 #define MIN_DOUBLE  2.2250738585072014e-308
3
4 double _xnextafter( double __x, double __y )
5 {
6         double_t *x = ( double_t *)&__x;
7         
8         double __e;
9         double_t *e = (double_t *)&__e;
10         
11         
12         if ( _isnan(__x) || _isinf(__x) )
13                 return __x;
14         
15         if ( _isnan(__y) )
16                 return __y;
17
18
19         // don't go to infinity just by adding
20
21         if ( _isinf(__y) && fabs(__x) >= MAX_DOUBLE  )
22                 return __x;
23
24         if ( !_isinf(__y) && fabs(__x - __y) <= MIN_DOUBLE  )
25                 return __y; 
26
27
28
29
30         e->mantissal = 1;
31         e->mantissah = 0;
32         if ( x->exponent >= 53  ) 
33                 e->exponent = x->exponent - 52;
34         else
35                 e->exponent = 1;
36
37         if ( fabs(__x) < fabs(__y) )
38                 e->sign = 0;
39         else
40                 e->sign = 1;
41
42
43
44     return __x+__e;
45
46
47
48 }