12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #if defined(LIBM_SCCS) && !defined(lint)
- static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp $";
- #endif
- #include "math.h"
- #include "math_private.h"
- #ifdef __STDC__
- double nextafter(double x, double y)
- #else
- double nextafter(x,y)
- double x,y;
- #endif
- {
- int32_t hx,hy,ix,iy;
- u_int32_t lx,ly;
- EXTRACT_WORDS(hx,lx,x);
- EXTRACT_WORDS(hy,ly,y);
- ix = hx&0x7fffffff;
- iy = hy&0x7fffffff;
- if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) ||
- ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0))
- return x+y;
- if(x==y) return x;
- if((ix|lx)==0) {
- INSERT_WORDS(x,hy&0x80000000,1);
- y = x*x;
- if(y==x) return y; else return x;
- }
- if(hx>=0) {
- if(hx>hy||((hx==hy)&&(lx>ly))) {
- if(lx==0) hx -= 1;
- lx -= 1;
- } else {
- lx += 1;
- if(lx==0) hx += 1;
- }
- } else {
- if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){
- if(lx==0) hx -= 1;
- lx -= 1;
- } else {
- lx += 1;
- if(lx==0) hx += 1;
- }
- }
- hy = hx&0x7ff00000;
- if(hy>=0x7ff00000) return x+x;
- if(hy<0x00100000) {
- y = x*x;
- if(y!=x) {
- INSERT_WORDS(y,hx,lx);
- return y;
- }
- }
- INSERT_WORDS(x,hx,lx);
- return x;
- }
|