00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00018
00019
00020
00021
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;
00040 iy = hy&0x7fffffff;
00041
00042
if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) ||
00043 ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0))
00044
return x+y;
00045
if(x==y)
return x;
00046
if((ix|lx)==0) {
00047
INSERT_WORDS(x,hy&0x80000000,1);
00048 y = x*x;
00049
if(y==x)
return y;
else return x;
00050 }
00051
if(hx>=0) {
00052
if(hx>hy||((hx==hy)&&(lx>ly))) {
00053
if(lx==0) hx -= 1;
00054 lx -= 1;
00055 }
else {
00056 lx += 1;
00057
if(lx==0) hx += 1;
00058 }
00059 }
else {
00060
if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){
00061
if(lx==0) hx -= 1;
00062 lx -= 1;
00063 }
else {
00064 lx += 1;
00065
if(lx==0) hx += 1;
00066 }
00067 }
00068 hy = hx&0x7ff00000;
00069
if(hy>=0x7ff00000)
return x+x;
00070
if(hy<0x00100000) {
00071 y = x*x;
00072
if(y!=x) {
00073
INSERT_WORDS(y,hx,lx);
00074
return y;
00075 }
00076 }
00077
INSERT_WORDS(x,hx,lx);
00078
return x;
00079 }