Print this page
11210 libm should be cstyle(1ONBLD) clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/m9x/nexttowardf.c
+++ new/usr/src/lib/libm/common/m9x/nexttowardf.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.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
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
20 20 */
21 21
22 22 /*
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 +
25 26 /*
26 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 28 * Use is subject to license terms.
28 29 */
29 30
30 31 #pragma weak nexttowardf = __nexttowardf
31 32
32 33 #include "libm.h"
33 34
34 35 static union {
35 36 unsigned i;
36 37 float f;
37 38 } C[] = {
38 - 0x00800000,
39 - 0x7f000000,
40 - 0x7fffffff
39 + 0x00800000, 0x7f000000, 0x7fffffff
41 40 };
42 41
43 -#define tiny C[0].f
44 -#define huge C[1].f
45 -#define qnan C[2].f
42 +#define tiny C[0].f
43 +#define huge C[1].f
44 +#define qnan C[2].f
46 45
47 46 #if defined(__sparc)
48 -
49 47 enum fcc_type {
50 - fcc_equal = 0,
51 - fcc_less = 1,
52 - fcc_greater = 2,
53 - fcc_unordered = 3
48 + fcc_equal = 0, fcc_less = 1, fcc_greater = 2, fcc_unordered = 3
54 49 };
55 50
56 51 #ifdef __sparcv9
57 52 #define _Q_cmp _Qp_cmp
58 53 #endif
59 54
60 55 extern enum fcc_type _Q_cmp(const long double *, const long double *);
61 56
62 57 float
63 -__nexttowardf(float x, long double y) {
58 +__nexttowardf(float x, long double y)
59 +{
64 60 union {
65 61 unsigned i;
66 62 float f;
67 63 } xx;
68 64 union {
69 65 unsigned i[4];
70 66 long double q;
71 67 } yy;
68 +
72 69 long double lx;
73 70 unsigned hx;
74 71 volatile float dummy;
75 72 enum fcc_type rel;
76 73
77 74 /*
78 75 * It would be somewhat more efficient to check for NaN and
79 76 * zero operands before converting x to long double and then
80 77 * to code the comparison in line rather than calling _Q_cmp.
81 78 * However, since this code probably won't get used much,
82 79 * I'm opting in favor of simplicity instead.
83 80 */
84 81 lx = xx.f = x;
85 82 hx = xx.i & ~0x80000000;
86 83
87 84 /* check for each of four possible orderings */
88 85 rel = _Q_cmp(&lx, &y);
86 +
89 87 if (rel == fcc_unordered)
90 88 return (qnan);
91 89
92 90 if (rel == fcc_equal) {
93 91 if (hx == 0) { /* x is zero; return zero with y's sign */
94 92 yy.q = y;
95 93 xx.i = yy.i[0];
96 94 return (xx.f);
97 95 }
96 +
98 97 return (x);
99 98 }
100 99
101 100 if (rel == fcc_less) {
102 - if (hx == 0) /* x is zero */
101 + if (hx == 0) /* x is zero */
103 102 xx.i = 0x00000001;
104 - else if ((int) xx.i >= 0) /* x is positive */
103 + else if ((int)xx.i >= 0) /* x is positive */
105 104 xx.i++;
106 105 else
107 106 xx.i--;
108 107 } else {
109 - if (hx == 0) /* x is zero */
108 + if (hx == 0) /* x is zero */
110 109 xx.i = 0x80000001;
111 - else if ((int) xx.i >= 0) /* x is positive */
110 + else if ((int)xx.i >= 0) /* x is positive */
112 111 xx.i--;
113 112 else
114 113 xx.i++;
115 114 }
116 115
117 116 /* raise exceptions as needed */
118 117 hx = xx.i & ~0x80000000;
118 +
119 119 if (hx == 0x7f800000) {
120 120 dummy = huge;
121 121 dummy *= huge;
122 122 } else if (hx < 0x00800000) {
123 123 dummy = tiny;
124 124 dummy *= tiny;
125 125 }
126 126
127 127 return (xx.f);
128 128 }
129 -
130 129 #elif defined(__x86)
131 -
132 130 float
133 -__nexttowardf(float x, long double y) {
131 +__nexttowardf(float x, long double y)
132 +{
134 133 union {
135 134 unsigned i;
136 135 float f;
137 136 } xx;
137 +
138 138 unsigned hx;
139 139 long double lx;
140 140 volatile float dummy;
141 141
142 142 lx = xx.f = x;
143 143 hx = xx.i & ~0x80000000;
144 144
145 145 /* check for each of four possible orderings */
146 146 if (isunordered(lx, y))
147 - return ((float) (lx + y));
147 + return ((float)(lx + y));
148 148
149 149 if (lx == y)
150 - return ((float) y);
150 + return ((float)y);
151 151
152 152 if (lx < y) {
153 - if (hx == 0) /* x is zero */
153 + if (hx == 0) /* x is zero */
154 154 xx.i = 0x00000001;
155 - else if ((int) xx.i >= 0) /* x is positive */
155 + else if ((int)xx.i >= 0) /* x is positive */
156 156 xx.i++;
157 157 else
158 158 xx.i--;
159 159 } else {
160 - if (hx == 0) /* x is zero */
160 + if (hx == 0) /* x is zero */
161 161 xx.i = 0x80000001;
162 - else if ((int) xx.i >= 0) /* x is positive */
162 + else if ((int)xx.i >= 0) /* x is positive */
163 163 xx.i--;
164 164 else
165 165 xx.i++;
166 166 }
167 167
168 168 /* raise exceptions as needed */
169 169 hx = xx.i & ~0x80000000;
170 +
170 171 if (hx == 0x7f800000) {
171 172 dummy = huge;
172 173 dummy *= huge;
173 174 } else if (hx < 0x00800000) {
174 175 dummy = tiny;
175 176 dummy *= tiny;
176 177 }
177 178
178 179 return (xx.f);
179 180 }
180 -
181 181 #else
182 182 #error Unknown architecture
183 183 #endif
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX