Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / msun / src / s_nextafter.c
1 /* @(#)s_nextafter.c 5.1 93/09/24 */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  *
12  * $FreeBSD: src/lib/msun/src/s_nextafter.c,v 1.5 1999/08/28 00:06:53 peter Exp $
13  * $DragonFly: src/lib/msun/src/Attic/s_nextafter.c,v 1.2 2003/06/17 04:26:53 dillon Exp $
14  */
15
16 /* IEEE functions
17  *      nextafter(x,y)
18  *      return the next machine floating-point number of x in the
19  *      direction toward y.
20  *   Special cases:
21  */
22
23 #include "math.h"
24 #include "math_private.h"
25
26 #ifdef __STDC__
27         double nextafter(double x, double y)
28 #else
29         double nextafter(x,y)
30         double x,y;
31 #endif
32 {
33         int32_t hx,hy,ix,iy;
34         u_int32_t lx,ly;
35
36         EXTRACT_WORDS(hx,lx,x);
37         EXTRACT_WORDS(hy,ly,y);
38         ix = hx&0x7fffffff;             /* |x| */
39         iy = hy&0x7fffffff;             /* |y| */
40
41         if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) ||   /* x is nan */
42            ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0))     /* y is nan */
43            return x+y;
44         if(x==y) return x;              /* x=y, return x */
45         if((ix|lx)==0) {                        /* x == 0 */
46             INSERT_WORDS(x,hy&0x80000000,1);    /* return +-minsubnormal */
47             y = x*x;
48             if(y==x) return y; else return x;   /* raise underflow flag */
49         }
50         if(hx>=0) {                             /* x > 0 */
51             if(hx>hy||((hx==hy)&&(lx>ly))) {    /* x > y, x -= ulp */
52                 if(lx==0) hx -= 1;
53                 lx -= 1;
54             } else {                            /* x < y, x += ulp */
55                 lx += 1;
56                 if(lx==0) hx += 1;
57             }
58         } else {                                /* x < 0 */
59             if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
60                 if(lx==0) hx -= 1;
61                 lx -= 1;
62             } else {                            /* x > y, x += ulp */
63                 lx += 1;
64                 if(lx==0) hx += 1;
65             }
66         }
67         hy = hx&0x7ff00000;
68         if(hy>=0x7ff00000) return x+x;  /* overflow  */
69         if(hy<0x00100000) {             /* underflow */
70             y = x*x;
71             if(y!=x) {          /* raise underflow flag */
72                 INSERT_WORDS(y,hx,lx);
73                 return y;
74             }
75         }
76         INSERT_WORDS(x,hx,lx);
77         return x;
78 }