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>
5262 libm needs to be carefully unifdef'd
5268 libm doesn't need to hide symbols which are already local
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/R/rintf.c
+++ new/usr/src/lib/libm/common/R/rintf.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 *
19 19 * CDDL HEADER END
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21
22 22 /*
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25 /*
26 26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 */
29 29
30 -#if defined(ELFOBJ)
31 -#pragma weak aintf = __aintf
32 -#pragma weak anintf = __anintf
33 -#pragma weak irintf = __irintf
34 -#pragma weak nintf = __nintf
35 -#pragma weak rintf = __rintf
36 -#endif
30 +#pragma weak __rintf = rintf
37 31
38 32 /* INDENT OFF */
39 33 /*
40 34 * aintf(x) return x chopped to integral value
41 35 * anintf(x) return sign(x)*(|x|+0.5) chopped to integral value
42 36 * irintf(x) return rint(x) in integer format
43 37 * nintf(x) return anint(x) in integer format
44 38 * rintf(x) return x rounded to integral according to the rounding direction
45 39 *
46 40 * NOTE: rintf(x), aintf(x) and anintf(x) return results with the same sign as
47 41 * x's, including 0.0.
48 42 */
49 43
50 44 #include "libm.h"
51 45
52 46 static const float xf[] = {
53 47 /* ZEROF */ 0.0f,
54 48 /* TWO_23F */ 8.3886080000e6f,
55 49 /* MTWO_23F */ -8.3886080000e6f,
56 50 /* ONEF */ 1.0f,
57 51 /* MONEF */ -1.0f,
58 52 /* HALFF */ 0.5f,
59 53 /* MHALFF */ -0.5f,
60 54 /* HUGEF */ 1.0e30f,
61 55 };
62 56
63 57 #define ZEROF xf[0]
64 58 #define TWO_23F xf[1]
65 59 #define MTWO_23F xf[2]
66 60 #define ONEF xf[3]
67 61 #define MONEF xf[4]
68 62 #define HALFF xf[5]
69 63 #define MHALFF xf[6]
70 64 #define HUGEF xf[7]
71 65 /* INDENT ON */
72 66
73 67 float
74 68 aintf(float x) {
75 69 int hx, k;
76 70 float y;
77 71
78 72 hx = *(int *) &x;
79 73 k = (hx & ~0x80000000) >> 23;
80 74 if (k < 150) {
81 75 y = (float) ((int) x);
82 76 /*
83 77 * make sure y has the same sign of x when |x|<0.5
84 78 * (i.e., y=0.0)
85 79 */
86 80 return (((k - 127) & hx) < 0 ? -y : y);
87 81 } else
88 82 /* signal invalid if x is a SNaN */
89 83 return (x * ONEF); /* +0 -> *1 for Cheetah */
90 84 }
91 85
92 86 float
93 87 anintf(float x) {
94 88 volatile float dummy;
95 89 int hx, k, j, ix;
96 90
97 91 hx = *(int *) &x;
98 92 ix = hx & ~0x80000000;
99 93 k = ix >> 23;
100 94 if (((k - 127) ^ (k - 150)) < 0) {
101 95 j = 1 << (149 - k);
102 96 k = j + j - 1;
103 97 if ((k & hx) != 0)
104 98 dummy = HUGEF + x; /* raise inexact */
105 99 *(int *) &x = (hx + j) & ~k;
106 100 return (x);
107 101 } else if (k <= 126) {
108 102 dummy = HUGEF + x;
109 103 *(int *) &x = (0x3f800000 & ((125 - k) >> 31)) |
110 104 (0x80000000 & hx);
111 105 return (x);
112 106 } else
113 107 /* signal invalid if x is a SNaN */
114 108 return (x * ONEF); /* +0 -> *1 for Cheetah */
115 109 }
116 110
117 111 int
118 112 irintf(float x) {
119 113 float v;
120 114 int hx, k;
121 115
122 116 hx = *(int *) &x;
123 117 k = (hx & ~0x80000000) >> 23;
124 118 v = xf[((k - 150) >> 31) & (1 - (hx >> 31))];
125 119 return ((int) ((float) (x + v) - v));
126 120 }
127 121
128 122 int
129 123 nintf(float x) {
130 124 int hx, ix, k, j, m;
131 125 volatile float dummy;
132 126
133 127 hx = *(int *) &x;
134 128 k = (hx & ~0x80000000) >> 23;
135 129 if (((k - 126) ^ (k - 150)) < 0) {
136 130 ix = (hx & 0x00ffffff) | 0x800000;
137 131 m = 149 - k;
138 132 j = 1 << m;
139 133 if ((ix & (j + j - 1)) != 0)
140 134 dummy = HUGEF + x;
141 135 hx = hx >> 31;
142 136 return ((((ix + j) >> (m + 1)) ^ hx) - hx);
143 137 } else
144 138 return ((int) x);
145 139 }
146 140
147 141 float
148 142 rintf(float x) {
149 143 float w, v;
150 144 int hx, k;
151 145
152 146 hx = *(int *) &x;
153 147 k = (hx & ~0x80000000) >> 23;
154 148 #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
155 149 if (k >= 150)
156 150 return (x * ONEF);
157 151 v = xf[1 - (hx >> 31)];
158 152 #else
159 153 v = xf[((k - 150) >> 31) & (1 - (hx >> 31))];
160 154 #endif
161 155 w = (float) (x + v);
162 156 if (k < 127 && w == v)
163 157 return (ZEROF * x);
164 158 else
165 159 return (w - v);
166 160 }
↓ open down ↓ |
120 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX