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