4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
30 * aintl(x) return x chopped to integral value
31 * anintl(x) return sign(x)*(|x|+0.5) chopped to integral value
32 * irintl(x) return rint(x) in integer format
33 * nintl(x) return anint(x) in integer format
35 * NOTE: aintl(x), anintl(x), ceill(x), floorl(x), and rintl(x) return result
36 * with the same sign as x's, including 0.0.
40 #include "longdouble.h"
42 extern enum fp_direction_type
__swapRD(enum fp_direction_type
);
44 static const long double qone
= 1.0L, qhalf
= 0.5L, qmhalf
= -0.5L;
47 aintl(long double x
) {
55 return (copysignl(t
, x
)); /* NaN or already aint(|x|) */
56 else /* |t|>|x| case */
57 return (copysignl(t
- qone
, x
)); /* |t-1|*sign(x) */
61 anintl(long double x
) {
69 return (copysignl(t
, x
));
75 return (copysignl(t
, x
));
79 irintl(long double x
) {
80 enum fp_direction_type rd
;
82 rd
= __swapRD(fp_nearest
);
83 (void) __swapRD(rd
); /* restore Rounding Direction */
86 if (x
< 2147483647.5L && x
>= -2147483648.5L)
87 return ((int)rintl(x
));
90 if (x
< 2147483648.0L && x
> -2147483649.0L)
91 return ((int)rintl(x
));
94 if (x
<= 2147483647.0L && x
> -2147483649.0L)
95 return ((int)rintl(x
));
98 if (x
< 2147483648.0L && x
>= -2147483648.0L)
99 return ((int)rintl(x
));
102 return ((int)copysignl(1.0e100L
, x
));
106 nintl(long double x
) {
107 if ((x
< 2147483647.5L) && (x
> -2147483648.5L))
108 return ((int)anintl(x
));
110 return ((int)copysignl(1.0e100L
, x
));