Print this page
5261 libm should stop using synonyms.h
5298 fabs is 0-sized, confuses dis(1) and others
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Gordon Ross <gwr@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/Q/rndintl.c
+++ new/usr/src/lib/libm/common/Q/rndintl.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23 23 */
24 24 /*
25 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 26 * Use is subject to license terms.
27 27 */
28 28
29 -#pragma weak aintl = __aintl
30 -#pragma weak anintl = __anintl
31 -#pragma weak irintl = __irintl
32 -#pragma weak nintl = __nintl
33 -
34 29 /*
35 30 * aintl(x) return x chopped to integral value
36 31 * anintl(x) return sign(x)*(|x|+0.5) chopped to integral value
37 32 * irintl(x) return rint(x) in integer format
38 33 * nintl(x) return anint(x) in integer format
39 34 *
40 35 * NOTE: aintl(x), anintl(x), ceill(x), floorl(x), and rintl(x) return result
41 36 * with the same sign as x's, including 0.0.
42 37 */
43 38
44 39 #include "libm.h"
45 40 #include "longdouble.h"
46 41
47 42 extern enum fp_direction_type __swapRD(enum fp_direction_type);
48 43
49 44 static const long double qone = 1.0L, qhalf = 0.5L, qmhalf = -0.5L;
50 45
51 46 long double
52 47 aintl(long double x) {
53 48 long double t, w;
54 49
55 50 if (!finitel(x))
56 51 return (x + x);
57 52 w = fabsl(x);
58 53 t = rintl(w);
59 54 if (t <= w)
60 55 return (copysignl(t, x)); /* NaN or already aint(|x|) */
61 56 else /* |t|>|x| case */
62 57 return (copysignl(t - qone, x)); /* |t-1|*sign(x) */
63 58 }
64 59
65 60 long double
66 61 anintl(long double x) {
67 62 long double t, w, z;
68 63
69 64 if (!finitel(x))
70 65 return (x + x);
71 66 w = fabsl(x);
72 67 t = rintl(w);
73 68 if (t == w)
74 69 return (copysignl(t, x));
75 70 z = t - w;
76 71 if (z > qhalf)
77 72 t = t - qone;
78 73 else if (z <= qmhalf)
79 74 t = t + qone;
80 75 return (copysignl(t, x));
81 76 }
82 77
83 78 int
84 79 irintl(long double x) {
85 80 enum fp_direction_type rd;
86 81
87 82 rd = __swapRD(fp_nearest);
88 83 (void) __swapRD(rd); /* restore Rounding Direction */
89 84 switch (rd) {
90 85 case fp_nearest:
91 86 if (x < 2147483647.5L && x >= -2147483648.5L)
92 87 return ((int)rintl(x));
93 88 break;
94 89 case fp_tozero:
95 90 if (x < 2147483648.0L && x > -2147483649.0L)
96 91 return ((int)rintl(x));
97 92 break;
98 93 case fp_positive:
99 94 if (x <= 2147483647.0L && x > -2147483649.0L)
100 95 return ((int)rintl(x));
101 96 break;
102 97 case fp_negative:
103 98 if (x < 2147483648.0L && x >= -2147483648.0L)
104 99 return ((int)rintl(x));
105 100 break;
106 101 }
107 102 return ((int)copysignl(1.0e100L, x));
108 103 }
109 104
110 105 int
111 106 nintl(long double x) {
112 107 if ((x < 2147483647.5L) && (x > -2147483648.5L))
113 108 return ((int)anintl(x));
114 109 else
115 110 return ((int)copysignl(1.0e100L, x));
116 111 }
↓ open down ↓ |
73 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX