1 /* origin: FreeBSD /usr/src/lib/msun/src/s_nextafterl.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 * ====================================================
14 * return the next machine floating-point number of x in the
21 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
22 long double nextafterl(long double x, long double y)
24 return nextafter(x, y);
26 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
27 long double nextafterl(long double x, long double y)
29 volatile long double t;
30 union IEEEl2bits ux, uy;
35 if ((ux.bits.exp == 0x7fff && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl) != 0) ||
36 (uy.bits.exp == 0x7fff && ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
37 return x+y; /* x or y is nan */
39 return y; /* x=y, return y */
41 /* return +-minsubnormal */
44 ux.bits.sign = uy.bits.sign;
45 /* raise underflow flag */
51 if(x > 0.0 ^ x < y) { /* x -= ulp */
52 if (ux.bits.manl == 0) {
53 if ((ux.bits.manh&~LDBL_NBIT) == 0)
55 ux.bits.manh = (ux.bits.manh - 1) | (ux.bits.manh & LDBL_NBIT);
58 } else { /* x += ulp */
60 if (ux.bits.manl == 0) {
61 ux.bits.manh = (ux.bits.manh + 1) | (ux.bits.manh & LDBL_NBIT);
62 if ((ux.bits.manh&~LDBL_NBIT)==0)
66 if (ux.bits.exp == 0x7fff) /* overflow */
68 if (ux.bits.exp == 0) { /* underflow */
70 /* raise underflow flag */