2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
14 * Return x rounded toward -inf to integral value
18 * Inexact flag raised if x not equal to ceill(x).
27 #ifdef LDBL_IMPLICIT_NBIT
28 #define MANH_SIZE (LDBL_MANH_SIZE + 1)
29 #define INC_MANH(u, c) do { \
30 uint64_t o = u.bits.manh; \
32 if (u.bits.manh < o) \
36 #define MANH_SIZE LDBL_MANH_SIZE
37 #define INC_MANH(u, c) do { \
38 uint64_t o = u.bits.manh; \
40 if (u.bits.manh < o) { \
42 u.bits.manh |= 1llu << (LDBL_MANH_SIZE - 1); \
47 static const long double huge = 1.0e300;
52 union IEEEl2bits u = { .e = x };
53 int e = u.bits.exp - LDBL_MAX_EXP + 1;
55 if (e < MANH_SIZE - 1) {
56 if (e < 0) { /* raise inexact if x != 0 */
59 (u.bits.manh | u.bits.manl) != 0)
60 u.e = u.bits.sign ? -0.0 : 1.0;
62 uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
63 if (((u.bits.manh & m) | u.bits.manl) == 0)
64 return (x); /* x is integral */
66 #ifdef LDBL_IMPLICIT_NBIT
71 INC_MANH(u, 1llu << (MANH_SIZE - e - 1));
73 if (huge + x > 0.0) { /* raise inexact flag */
78 } else if (e < LDBL_MANT_DIG - 1) {
79 uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
80 if ((u.bits.manl & m) == 0)
81 return (x); /* x is integral */
83 if (e == MANH_SIZE - 1)
86 uint64_t o = u.bits.manl;
87 u.bits.manl += 1llu << (LDBL_MANT_DIG - e - 1);
88 if (u.bits.manl < o) /* got a carry */
92 if (huge + x > 0.0) /* raise inexact flag */