12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #include <float.h>
- #include <openlibm_math.h>
- #include "math_private.h"
- float
- nexttowardf(float x, long double y)
- {
- int32_t hx,ix,iy;
- u_int32_t hy,ly,esy;
- GET_FLOAT_WORD(hx,x);
- GET_LDOUBLE_WORDS(esy,hy,ly,y);
- ix = hx&0x7fffffff;
- iy = esy&0x7fff;
- if((ix>0x7f800000) ||
- (iy>=0x7fff&&((hy|ly)!=0)))
- return x+y;
- if((long double) x==y) return y;
- if(ix==0) {
- volatile float u;
- SET_FLOAT_WORD(x,((esy&0x8000)<<16)|1);
- u = x;
- u = u * u;
- return x;
- }
- if(hx>=0) {
- if(esy>=0x8000||((ix>>23)&0xff)>iy-0x3f80
- || (((ix>>23)&0xff)==iy-0x3f80
- && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {
- hx -= 1;
- } else {
- hx += 1;
- }
- } else {
- if(esy<0x8000||((ix>>23)&0xff)>iy-0x3f80
- || (((ix>>23)&0xff)==iy-0x3f80
- && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {
- hx -= 1;
- } else {
- hx += 1;
- }
- }
- hy = hx&0x7f800000;
- if(hy>=0x7f800000) {
- x = x+x;
- return x;
- }
- if(hy<0x00800000) {
- volatile float u = x*x;
- }
- SET_FLOAT_WORD(x,hx);
- return x;
- }
|