base/math/s_nextafter.c

Go to the documentation of this file.
00001 /* @(#)s_nextafter.c 5.1 93/09/24 */ 00002 /* 00003 * ==================================================== 00004 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 00005 * 00006 * Developed at SunPro, a Sun Microsystems, Inc. business. 00007 * Permission to use, copy, modify, and distribute this 00008 * software is freely granted, provided that this notice 00009 * is preserved. 00010 * ==================================================== 00011 */ 00012 00013 #if defined(LIBM_SCCS) && !defined(lint) 00014 static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp $"; 00015 #endif 00016 00017 /* IEEE functions 00018 * nextafter(x,y) 00019 * return the next machine floating-point number of x in the 00020 * direction toward y. 00021 * Special cases: 00022 */ 00023 00024 #include "math.h" 00025 #include "mathP.h" 00026 00027 #ifdef __STDC__ 00028 double nextafter(double x, double y) 00029 #else 00030 double nextafter(x,y) 00031 double x,y; 00032 #endif 00033 { 00034 int32_t hx,hy,ix,iy; 00035 u_int32_t lx,ly; 00036 00037 EXTRACT_WORDS(hx,lx,x); 00038 EXTRACT_WORDS(hy,ly,y); 00039 ix = hx&0x7fffffff; /* |x| */ 00040 iy = hy&0x7fffffff; /* |y| */ 00041 00042 if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ 00043 ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ 00044 return x+y; 00045 if(x==y) return x; /* x=y, return x */ 00046 if((ix|lx)==0) { /* x == 0 */ 00047 INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */ 00048 y = x*x; 00049 if(y==x) return y; else return x; /* raise underflow flag */ 00050 } 00051 if(hx>=0) { /* x > 0 */ 00052 if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ 00053 if(lx==0) hx -= 1; 00054 lx -= 1; 00055 } else { /* x < y, x += ulp */ 00056 lx += 1; 00057 if(lx==0) hx += 1; 00058 } 00059 } else { /* x < 0 */ 00060 if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */ 00061 if(lx==0) hx -= 1; 00062 lx -= 1; 00063 } else { /* x > y, x += ulp */ 00064 lx += 1; 00065 if(lx==0) hx += 1; 00066 } 00067 } 00068 hy = hx&0x7ff00000; 00069 if(hy>=0x7ff00000) return x+x; /* overflow */ 00070 if(hy<0x00100000) { /* underflow */ 00071 y = x*x; 00072 if(y!=x) { /* raise underflow flag */ 00073 INSERT_WORDS(y,hx,lx); 00074 return y; 00075 } 00076 } 00077 INSERT_WORDS(x,hx,lx); 00078 return x; 00079 }

Generated on Thu Nov 20 11:49:52 2008 for RTAI API by doxygen 1.3.8