1 /* @(#)s_nextafter.c 5.1 93/09/24 */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
15 * return the next machine floating-point number of x in the
22 #include "math_private.h"
25 nextafterl(long double x, long double y)
28 u_int32_t lx,ly,esx,esy;
30 GET_LDOUBLE_WORDS(esx,hx,lx,x);
31 GET_LDOUBLE_WORDS(esy,hy,ly,y);
32 ix = esx&0x7fff; /* |x| */
33 iy = esy&0x7fff; /* |y| */
35 if (((ix==0x7fff)&&((hx&0x7fffffff|lx)!=0)) || /* x is nan */
36 ((iy==0x7fff)&&((hy&0x7fffffff|ly)!=0))) /* y is nan */
38 if(x==y) return y; /* x=y, return y */
39 if((ix|hx|lx)==0) { /* x == 0 */
40 volatile long double u;
41 SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */
43 u = u * u; /* raise underflow flag */
46 if(esx<0x8000) { /* x > 0 */
47 if(ix>iy||((ix==iy) && (hx>hy||((hx==hy)&&(lx>ly))))) {
50 if ((hx&0x7fffffff)==0) esx -= 1;
51 hx = (hx - 1) | (hx & 0x80000000);
54 } else { /* x < y, x += ulp */
57 hx = (hx + 1) | (hx & 0x80000000);
58 if ((hx&0x7fffffff)==0) esx += 1;
62 if(esy>=0||(ix>iy||((ix==iy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){
65 if ((hx&0x7fffffff)==0) esx -= 1;
66 hx = (hx - 1) | (hx & 0x80000000);
69 } else { /* x > y, x += ulp */
72 hx = (hx + 1) | (hx & 0x80000000);
73 if ((hx&0x7fffffff)==0) esx += 1;
78 if(esy==0x7fff) return x+x; /* overflow */
80 volatile long double u = x*x; /* underflow */
82 SET_LDOUBLE_WORDS(x,esx,hx,lx);
86 SET_LDOUBLE_WORDS(x,esx,hx,lx);
90 __strong_alias(nexttowardl, nextafterl);