1 /* origin: FreeBSD /usr/src/lib/msun/src/s_truncl.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 x rounded toward 0 to integral value
18 * Inexact flag raised if x not equal to truncl(x).
23 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
24 long double truncl(long double x)
28 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
29 #ifdef LDBL_IMPLICIT_NBIT
30 #define MANH_SIZE (LDBL_MANH_SIZE + 1)
32 #define MANH_SIZE LDBL_MANH_SIZE
35 static const long double huge = 1.0e300;
36 static const float zero[] = { 0.0, -0.0 };
38 long double truncl(long double x)
40 union IEEEl2bits u = { .e = x };
41 int e = u.bits.exp - LDBL_MAX_EXP + 1;
43 if (e < MANH_SIZE - 1) {
45 /* raise inexact if x != 0 */
47 u.e = zero[u.bits.sign];
49 uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
50 if (((u.bits.manh & m) | u.bits.manl) == 0)
51 return x; /* x is integral */
58 } else if (e < LDBL_MANT_DIG - 1) {
59 uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
60 if ((u.bits.manl & m) == 0)
61 return x; /* x is integral */