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