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/LD/hypotl.c
+++ new/usr/src/lib/libm/common/LD/hypotl.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 hypotl = __hypotl
32 -#endif
30 +#pragma weak __hypotl = hypotl
33 31
34 32 /*
35 33 * hypotl(x,y)
36 34 * Method :
37 35 * If z=x*x+y*y has error less than sqrt(2)/2 ulp than sqrt(z) has
38 36 * error less than 1 ulp.
39 37 * So, compute sqrt(x*x+y*y) with some care as follows:
40 38 * Assume x>y>0;
41 39 * 1. save and set rounding to round-to-nearest
42 40 * 2. if x > 2y use
43 41 * x1*x1+(y*y+(x2*(x+x2))) for x*x+y*y
44 42 * where x1 = x with lower 32 bits cleared, x2 = x-x1; else
45 43 * 3. if x <= 2y use
46 44 * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y))
47 45 * where t1 = 2x with lower 64 bits cleared, t2 = 2x-t1, y1= y with
48 46 * lower 32 bits cleared, y2 = y-y1.
49 47 *
50 48 * NOTE: DO NOT remove parenthsis!
51 49 *
52 50 * Special cases:
53 51 * hypot(x,y) is INF if x or y is +INF or -INF; else
54 52 * hypot(x,y) is NAN if x or y is NAN.
55 53 *
56 54 * Accuracy:
57 55 * hypot(x,y) returns sqrt(x^2+y^2) with error less than 1 ulps (units
58 56 * in the last place)
59 57 */
60 58
61 59 #include "libm.h"
62 60
63 61 #if defined(__x86)
64 62 extern enum fp_direction_type __swap87RD(enum fp_direction_type);
65 63
66 64 #define k 0x7fff
67 65
68 66 long double
69 67 hypotl(long double x, long double y) {
70 68 long double t1, t2, y1, y2, w;
71 69 int *px = (int *) &x, *py = (int *) &y;
72 70 int *pt1 = (int *) &t1, *py1 = (int *) &y1;
73 71 enum fp_direction_type rd;
74 72 int j, nx, ny, nz;
75 73
76 74 px[2] &= 0x7fff; /* clear sign bit and padding bits of x and y */
77 75 py[2] &= 0x7fff;
78 76 nx = px[2]; /* biased exponent of x and y */
79 77 ny = py[2];
80 78 if (ny > nx) {
81 79 w = x;
82 80 x = y;
83 81 y = w;
84 82 nz = ny;
85 83 ny = nx;
86 84 nx = nz;
87 85 } /* force nx >= ny */
88 86 if (nx - ny >= 66)
89 87 return (x + y); /* x / y >= 2**65 */
90 88 if (nx < 0x5ff3 && ny > 0x205b) { /* medium x,y */
91 89 /* save and set RD to Rounding to nearest */
92 90 rd = __swap87RD(fp_nearest);
93 91 w = x - y;
94 92 if (w > y) {
95 93 pt1[2] = px[2];
96 94 pt1[1] = px[1];
97 95 pt1[0] = 0;
98 96 t2 = x - t1;
99 97 x = sqrtl(t1 * t1 - (y * (-y) - t2 * (x + t1)));
100 98 } else {
101 99 x += x;
102 100 py1[2] = py[2];
103 101 py1[1] = py[1];
104 102 py1[0] = 0;
105 103 y2 = y - y1;
106 104 pt1[2] = px[2];
107 105 pt1[1] = px[1];
108 106 pt1[0] = 0;
109 107 t2 = x - t1;
110 108 x = sqrtl(t1 * y1 - (w * (-w) - (t2 * y1 + y2 * x)));
111 109 }
112 110 if (rd != fp_nearest)
113 111 __swap87RD(rd); /* restore rounding mode */
114 112 return (x);
115 113 } else {
116 114 if (nx == k || ny == k) { /* x or y is INF or NaN */
117 115 /* since nx >= ny; nx is always k within this block */
118 116 if (px[1] == 0x80000000 && px[0] == 0)
119 117 return (x);
120 118 else if (ny == k && py[1] == 0x80000000 && py[0] == 0)
121 119 return (y);
122 120 else
123 121 return (x + y);
124 122 }
125 123 if (ny == 0) {
126 124 if (y == 0.L || x == 0.L)
127 125 return (x + y);
128 126 pt1[2] = 0x3fff + 16381;
129 127 pt1[1] = 0x80000000;
130 128 pt1[0] = 0;
131 129 py1[2] = 0x3fff - 16381;
132 130 py1[1] = 0x80000000;
133 131 py1[0] = 0;
134 132 x *= t1;
135 133 y *= t1;
136 134 return (y1 * hypotl(x, y));
137 135 }
138 136 j = nx - 0x3fff;
139 137 px[2] -= j;
140 138 py[2] -= j;
141 139 pt1[2] = nx;
142 140 pt1[1] = 0x80000000;
143 141 pt1[0] = 0;
144 142 return (t1 * hypotl(x, y));
145 143 }
146 144 }
147 145 #endif
↓ open down ↓ |
105 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX