123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "cdefs-compat.h"
- #include <float.h>
- #include <openlibm_math.h>
- #include "fpmath.h"
- #include "math_private.h"
- #if LDBL_MAX_EXP != 0x4000
- #error "Unsupported long double format"
- #endif
- OLM_DLLEXPORT double
- nexttoward(double x, long double y)
- {
- union IEEEl2bits uy;
- volatile double t;
- int32_t hx,ix;
- u_int32_t lx;
- EXTRACT_WORDS(hx,lx,x);
- ix = hx&0x7fffffff;
- uy.e = y;
- if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) ||
- (uy.bits.exp == 0x7fff &&
- ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
- return x+y;
- if(x==y) return (double)y;
- if(x==0.0) {
- INSERT_WORDS(x,uy.bits.sign<<31,1);
- t = x*x;
- if(t==x) return t; else return x;
- }
- if((hx>0.0) ^ (x < y)) {
- if(lx==0) hx -= 1;
- lx -= 1;
- } else {
- lx += 1;
- if(lx==0) hx += 1;
- }
- ix = hx&0x7ff00000;
- if(ix>=0x7ff00000) return x+x;
- if(ix<0x00100000) {
- t = x*x;
- if(t!=x) {
- INSERT_WORDS(x,hx,lx);
- return x;
- }
- }
- INSERT_WORDS(x,hx,lx);
- return x;
- }
|