1 /* origin: FreeBSD /usr/src/lib/msun/src/s_nexttowardf.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
17 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
18 #define LDBL_INFNAN_EXP (LDBL_MAX_EXP * 2 - 1)
20 float nexttowardf(float x, long double y)
26 GET_FLOAT_WORD(hx, x);
27 ix = hx & 0x7fffffff; /* |x| */
30 if (ix > 0x7f800000 ||
31 (uy.bits.exp == LDBL_INFNAN_EXP &&
32 ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
33 return x + y; /* x or y is nan */
35 return (float)y; /* x=y, return y */
36 if (ix == 0) { /* x == 0 */
37 SET_FLOAT_WORD(x, (uy.bits.sign<<31)|1); /* return +-minsubnormal */
38 /* raise underflow flag */
44 if (hx >= 0 ^ x < y) /* x -= ulp */
49 if (ix >= 0x7f800000) /* overflow */
51 if (ix < 0x00800000) { /* underflow */
52 /* raise underflow flag */
55 SET_FLOAT_WORD(x, hx);
59 SET_FLOAT_WORD(x, hx);