123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "math.h"
- #include "math_private.h"
- #include <float.h>
- double nextafter(double x, double y)
- {
- 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 y;
- 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;
- }
- libm_hidden_def(nextafter)
- #if LDBL_MANT_DIG == DBL_MANT_DIG
- strong_alias_untyped(nextafter, nexttoward)
- libm_hidden_def(nexttoward)
- #else
- double nexttoward(double x, long double y)
- {
- return nextafter(x, y);
- }
- libm_hidden_def(nexttoward)
- #endif
|