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
21 #include <sys/cdefs.h>
23 #include "math_private.h"
26 nextafterl(long double x, long double y)
32 GET_LDOUBLE_WORDS(esx,hx,lx,x);
33 GET_LDOUBLE_WORDS(esy,hy,ly,y);
34 ix = esx&0x7fff; /* |x| */
35 iy = esy&0x7fff; /* |y| */
37 if (((ix==0x7fff)&&(((hx&0x7fffffff)|lx)!=0)) || /* x is nan */
38 ((iy==0x7fff)&&(((hy&0x7fffffff)|ly)!=0))) /* y is nan */
40 if(x==y) return y; /* x=y, return y */
41 if((ix|hx|lx)==0) { /* x == 0 */
42 volatile long double u;
43 SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */
45 u = u * u; /* raise underflow flag */
48 if(esx<0x8000) { /* x > 0 */
49 if(ix>iy||((ix==iy) && (hx>hy||((hx==hy)&&(lx>ly))))) {
52 if ((hx&0x7fffffff)==0) esx -= 1;
53 hx = (hx - 1) | (hx & 0x80000000);
56 } else { /* x < y, x += ulp */
59 hx = (hx + 1) | (hx & 0x80000000);
60 if ((hx&0x7fffffff)==0) esx += 1;
64 if(esy>=0||(ix>iy||((ix==iy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){
67 if ((hx&0x7fffffff)==0) esx -= 1;
68 hx = (hx - 1) | (hx & 0x80000000);
71 } else { /* x > y, x += ulp */
74 hx = (hx + 1) | (hx & 0x80000000);
75 if ((hx&0x7fffffff)==0) esx += 1;
80 if(esy==0x7fff) return x+x; /* overflow */
82 volatile long double u = x*x; /* underflow */
84 SET_LDOUBLE_WORDS(x,esx,hx,lx);
88 SET_LDOUBLE_WORDS(x,esx,hx,lx);
92 __strong_reference(nextafterl, nexttowardl);