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>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/C/exp10.c
+++ new/usr/src/lib/libm/common/C/exp10.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 2006 Sun Microsystems, Inc. All rights reserved.
26 26 * Use is subject to license terms.
27 27 */
28 28
29 -#pragma weak exp10 = __exp10
30 -
31 29 /* INDENT OFF */
32 30 /*
33 31 * exp10(x)
34 32 * Code by K.C. Ng for SUN 4.0 libm.
35 33 * Method :
36 34 * n = nint(x*(log10/log2));
37 35 * exp10(x) = 10**x = exp(x*ln(10)) = exp(n*ln2+(x*ln10-n*ln2))
38 36 * = 2**n*exp(ln10*(x-n*log2/log10)))
39 37 * If x is an integer < 23 then use repeat multiplication. For
40 38 * 10**22 is the largest representable integer.
41 39 */
42 40 /* INDENT ON */
43 41
44 42 #include "libm.h"
45 43
46 44 static const double C[] = {
47 45 3.3219280948736234787, /* log(10)/log(2) */
48 46 2.3025850929940456840, /* log(10) */
49 47 3.0102999565860955045E-1, /* log(2)/log(10) high */
50 48 5.3716447674669983622E-12, /* log(2)/log(10) low */
51 49 0.0,
52 50 0.5,
53 51 1.0,
54 52 10.0,
55 53 1.0e300,
56 54 1.0e-300,
57 55 };
58 56
59 57 #define lg10 C[0]
60 58 #define ln10 C[1]
61 59 #define logt2hi C[2]
62 60 #define logt2lo C[3]
63 61 #define zero C[4]
64 62 #define half C[5]
65 63 #define one C[6]
66 64 #define ten C[7]
67 65 #define huge C[8]
68 66 #define tiny C[9]
69 67
70 68 double
71 69 exp10(double x) {
72 70 double t, pt;
73 71 int ix, hx, k;
74 72
75 73 ix = ((int *)&x)[HIWORD];
76 74 hx = ix & ~0x80000000;
77 75
78 76 if (hx >= 0x4074a000) { /* |x| >= 330 or x is nan */
79 77 if (hx >= 0x7ff00000) { /* x is inf or nan */
80 78 if (ix == 0xfff00000 && ((int *)&x)[LOWORD] == 0)
81 79 return (zero);
82 80 return (x * x);
83 81 }
84 82 t = (ix < 0)? tiny : huge;
85 83 return (t * t);
86 84 }
87 85
88 86 if (hx < 0x3c000000)
89 87 return (one + x);
90 88
91 89 k = (int)x;
92 90 if (0 <= k && k < 23 && (double)k == x) {
93 91 /* x is a small positive integer */
94 92 t = one;
95 93 pt = ten;
96 94 if (k & 1)
97 95 t = ten;
98 96 k >>= 1;
99 97 while (k) {
100 98 pt *= pt;
101 99 if (k & 1)
102 100 t *= pt;
103 101 k >>= 1;
104 102 }
105 103 return (t);
106 104 }
107 105 t = x * lg10;
108 106 k = (int)((ix < 0)? t - half : t + half);
109 107 return (scalbn(exp(ln10 * ((x - k * logt2hi) - k * logt2lo)), k));
110 108 }
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX