Print this page
5261 libm should stop using synonyms.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/R/fmodf.c
+++ new/usr/src/lib/libm/common/R/fmodf.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 fmodf = __fmodf
29 +#pragma weak __fmodf = fmodf
30 30
31 31 #include "libm.h"
32 32
33 33 /* INDENT OFF */
34 34 static const int
35 35 is = (int)0x80000000,
36 36 im = 0x007fffff,
37 37 ii = 0x7f800000,
38 38 iu = 0x00800000;
39 39 /* INDENT ON */
40 40
41 41 static const float zero = 0.0;
42 42
43 43 float
44 44 fmodf(float x, float y) {
45 45 float w;
46 46 int hx, ix, iy, iz, k, ny, nd;
47 47
48 48 hx = *(int *)&x;
49 49 ix = hx & 0x7fffffff;
50 50 iy = *(int *)&y & 0x7fffffff;
51 51
52 52 /* purge off exception values */
53 53 if (ix >= ii || iy > ii || iy == 0) {
54 54 w = x * y;
55 55 w = w / w;
56 56 } else if (ix <= iy) {
57 57 if (ix < iy)
58 58 w = x; /* return x if |x|<|y| */
59 59 else
60 60 w = zero * x; /* return sign(x)*0.0 */
61 61 } else {
62 62 /* INDENT OFF */
63 63 /*
64 64 * scale x,y to "normal" with
65 65 * ny = exponent of y
66 66 * nd = exponent of x minus exponent of y
67 67 */
68 68 /* INDENT ON */
69 69 ny = iy >> 23;
70 70 k = ix >> 23;
71 71
72 72 /* special case for subnormal y or x */
73 73 if (ny == 0) {
74 74 ny = 1;
75 75 while (iy < iu) {
76 76 ny -= 1;
77 77 iy += iy;
78 78 }
79 79 nd = k - ny;
80 80 if (k == 0) {
81 81 nd += 1;
82 82 while (ix < iu) {
83 83 nd -= 1;
84 84 ix += ix;
85 85 }
86 86 } else {
87 87 ix = iu | (ix & im);
88 88 }
89 89 } else {
90 90 nd = k - ny;
91 91 ix = iu | (ix & im);
92 92 iy = iu | (iy & im);
93 93 }
94 94
95 95 /* fix point fmod for normalized ix and iy */
96 96 /* INDENT OFF */
97 97 /*
98 98 * while (nd--) {
99 99 * iz = ix - iy;
100 100 * if (iz < 0)
101 101 * ix = ix + ix;
102 102 * else if (iz == 0) {
103 103 * *(int *) &w = is & hx;
104 104 * return w;
105 105 * }
106 106 * else
107 107 * ix = iz + iz;
108 108 * }
109 109 */
110 110 /* INDENT ON */
111 111 /* unroll the above loop 4 times to gain performance */
112 112 k = nd >> 2;
113 113 nd -= k << 2;
114 114 while (k--) {
115 115 iz = ix - iy;
116 116 if (iz >= 0)
117 117 ix = iz + iz;
118 118 else
119 119 ix += ix;
120 120 iz = ix - iy;
121 121 if (iz >= 0)
122 122 ix = iz + iz;
123 123 else
124 124 ix += ix;
125 125 iz = ix - iy;
126 126 if (iz >= 0)
127 127 ix = iz + iz;
128 128 else
129 129 ix += ix;
130 130 iz = ix - iy;
131 131 if (iz >= 0)
132 132 ix = iz + iz;
133 133 else
134 134 ix += ix;
135 135 if (iz == 0) {
136 136 *(int *)&w = is & hx;
137 137 return (w);
138 138 }
139 139 }
140 140 while (nd--) {
141 141 iz = ix - iy;
142 142 if (iz >= 0)
143 143 ix = iz + iz;
144 144 else
145 145 ix += ix;
146 146 }
147 147 /* end of unrolling */
148 148
149 149 iz = ix - iy;
150 150 if (iz >= 0)
151 151 ix = iz;
152 152
153 153 /* convert back to floating value and restore the sign */
154 154 if (ix == 0) {
155 155 *(int *)&w = is & hx;
156 156 return (w);
157 157 }
158 158 while (ix < iu) {
159 159 ix += ix;
160 160 ny -= 1;
161 161 }
162 162 while (ix > (iu + iu)) {
163 163 ny += 1;
164 164 ix >>= 1;
165 165 }
166 166 if (ny > 0) {
167 167 *(int *)&w = (is & hx) | (ix & im) | (ny << 23);
168 168 } else {
169 169 /* subnormal output */
170 170 k = -ny + 1;
171 171 ix >>= k;
172 172 *(int *)&w = (is & hx) | ix;
173 173 }
174 174 }
175 175 return (w);
176 176 }
↓ open down ↓ |
137 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX