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 * ====================================================
11 * From: @(#)s_floor.c 5.1 93/09/24
15 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/s_truncl.c,v 1.4 2005/04/28 19:45:55 stefanf Exp $";
20 * Return x rounded toward 0 to integral value
24 * Inexact flag raised if x not equal to truncl(x).
33 #ifdef LDBL_IMPLICIT_NBIT
34 #define MANH_SIZE (LDBL_MANH_SIZE + 1)
36 #define MANH_SIZE LDBL_MANH_SIZE
39 static const long double huge
= 1.0e300
;
44 union IEEEl2bits u
= { .e
= x
};
45 int e
= u
.bits
.exp
- LDBL_MAX_EXP
+ 1;
47 if (e
< MANH_SIZE
- 1) {
48 if (e
< 0) { /* raise inexact if x != 0 */
52 uint64_t m
= ((1llu << MANH_SIZE
) - 1) >> (e
+ 1);
53 if (((u
.bits
.manh
& m
) | u
.bits
.manl
) == 0)
54 return (x
); /* x is integral */
55 if (huge
+ x
> 0.0) { /* raise inexact flag */
60 } else if (e
< LDBL_MANT_DIG
- 1) {
61 uint64_t m
= (uint64_t)-1 >> (64 - LDBL_MANT_DIG
+ e
+ 1);
62 if ((u
.bits
.manl
& m
) == 0)
63 return (x
); /* x is integral */
64 if (huge
+ x
> 0.0) /* raise inexact flag */