1 /* origin: FreeBSD /usr/src/lib/msun/src/s_nexttoward.c */
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 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
16 double nexttoward(double x, long double y)
18 return nextafter(x, y);
20 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
21 double nexttoward(double x, long double y)
28 EXTRACT_WORDS(hx, lx, x);
32 if ((ix >= 0x7ff00000 && ((ix-0x7ff00000)|lx) != 0) ||
33 (uy.bits.exp == 0x7fff && ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
34 return x + y; /* x or y is nan */
38 INSERT_WORDS(x, uy.bits.sign<<31, 1); /* return +-minsubnormal */
45 if (hx > 0.0 ^ x < y) { /* x -= ulp */
49 } else { /* x += ulp */
55 if (ix >= 0x7ff00000) /* overflow */
57 if (ix < 0x00100000) { /* underflow */
58 /* raise underflow flag */
61 INSERT_WORDS(x, hx, lx);
65 INSERT_WORDS(x, hx, lx);