nextafterq.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* nextafterq.c -- __float128 version of s_nextafter.c.
  2. * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
  3. */
  4. /*
  5. * ====================================================
  6. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7. *
  8. * Developed at SunPro, a Sun Microsystems, Inc. business.
  9. * Permission to use, copy, modify, and distribute this
  10. * software is freely granted, provided that this notice
  11. * is preserved.
  12. * ====================================================
  13. */
  14. #include "quadmath-imp.h"
  15. __float128
  16. nextafterq (__float128 x, __float128 y)
  17. {
  18. int64_t hx,hy,ix,iy;
  19. uint64_t lx,ly;
  20. GET_FLT128_WORDS64(hx,lx,x);
  21. GET_FLT128_WORDS64(hy,ly,y);
  22. ix = hx&0x7fffffffffffffffLL; /* |x| */
  23. iy = hy&0x7fffffffffffffffLL; /* |y| */
  24. if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) || /* x is nan */
  25. ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0)) /* y is nan */
  26. return x+y;
  27. if(x==y) return y; /* x=y, return y */
  28. if((ix|lx)==0) { /* x == 0 */
  29. SET_FLT128_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */
  30. /* here we should raise an underflow flag */
  31. return x;
  32. }
  33. if(hx>=0) { /* x > 0 */
  34. if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
  35. if(lx==0) hx--;
  36. lx--;
  37. } else { /* x < y, x += ulp */
  38. lx++;
  39. if(lx==0) hx++;
  40. }
  41. } else { /* x < 0 */
  42. if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
  43. if(lx==0) hx--;
  44. lx--;
  45. } else { /* x > y, x += ulp */
  46. lx++;
  47. if(lx==0) hx++;
  48. }
  49. }
  50. hy = hx&0x7fff000000000000LL;
  51. if(hy==0x7fff000000000000LL) return x+x;/* overflow */
  52. if(hy==0) {
  53. /* here we should raise an underflow flag */
  54. }
  55. SET_FLT128_WORDS64(x,hx,lx);
  56. return x;
  57. }