Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4973 | right-hear | 1 | /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ |
2 | /* @(#)s_nextafter.c 5.1 93/09/24 */ |
||
3 | /* |
||
4 | * ==================================================== |
||
5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
||
6 | * |
||
7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
||
8 | * Permission to use, copy, modify, and distribute this |
||
9 | * software is freely granted, provided that this notice |
||
10 | * is preserved. |
||
11 | * ==================================================== |
||
12 | */ |
||
13 | |||
14 | #if defined(LIBM_SCCS) && !defined(lint) |
||
15 | static char rcsid[] = "$Id: s_nextafter.c,v 1.6 1994/08/18 23:07:13 jtc Exp $"; |
||
16 | #endif |
||
17 | |||
18 | /* IEEE functions |
||
19 | * nextafter(x,y) |
||
20 | * return the next machine floating-point number of x in the |
||
21 | * direction toward y. |
||
22 | * Special cases: |
||
23 | */ |
||
24 | |||
25 | #include "math.h" |
||
26 | #include "math_private.h" |
||
27 | |||
28 | #ifdef __STDC__ |
||
29 | double nextafter(double x, double y) |
||
30 | #else |
||
31 | double nextafter(x,y) |
||
32 | double x,y; |
||
33 | #endif |
||
34 | { |
||
35 | int32_t hx,hy,ix,iy; |
||
36 | u_int32_t lx,ly; |
||
37 | |||
38 | EXTRACT_WORDS(hx,lx,x); |
||
39 | EXTRACT_WORDS(hy,ly,y); |
||
40 | ix = hx&0x7fffffff; /* |x| */ |
||
41 | iy = hy&0x7fffffff; /* |y| */ |
||
42 | |||
43 | if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ |
||
44 | ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ |
||
45 | return x+y; |
||
46 | if(x==y) return x; /* x=y, return x */ |
||
47 | if((ix|lx)==0) { /* x == 0 */ |
||
48 | INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */ |
||
49 | y = x*x; |
||
50 | if(y==x) return y; else return x; /* raise underflow flag */ |
||
51 | } |
||
52 | if(hx>=0) { /* x > 0 */ |
||
53 | if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ |
||
54 | if(lx==0) hx -= 1; |
||
55 | lx -= 1; |
||
56 | } else { /* x < y, x += ulp */ |
||
57 | lx += 1; |
||
58 | if(lx==0) hx += 1; |
||
59 | } |
||
60 | } else { /* x < 0 */ |
||
61 | if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */ |
||
62 | if(lx==0) hx -= 1; |
||
63 | lx -= 1; |
||
64 | } else { /* x > y, x += ulp */ |
||
65 | lx += 1; |
||
66 | if(lx==0) hx += 1; |
||
67 | } |
||
68 | } |
||
69 | hy = hx&0x7ff00000; |
||
70 | if(hy>=0x7ff00000) return x+x; /* overflow */ |
||
71 | if(hy<0x00100000) { /* underflow */ |
||
72 | y = x*x; |
||
73 | if(y!=x) { /* raise underflow flag */ |
||
74 | INSERT_WORDS(y,hx,lx); |
||
75 | return y; |
||
76 | } |
||
77 | } |
||
78 | INSERT_WORDS(x,hx,lx); |
||
79 | return x; |
||
80 | }0x00100000)>>>> |