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/Q/coshl.c
+++ new/usr/src/lib/libm/common/Q/coshl.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 coshl = __coshl
30 +#pragma weak __coshl = coshl
31 31
32 32 #include "libm.h"
33 33 #include "longdouble.h"
34 34
35 35
36 36 /*
37 37 * coshl(X)
38 38 * RETURN THE HYPERBOLIC COSINE OF X
39 39 *
40 40 * Method :
41 41 * 1. Replace x by |x| (coshl(x) = coshl(-x)).
42 42 * 2.
43 43 * [ expl(x) - 1 ]^2
44 44 * 0 <= x <= 0.3465 : coshl(x) := 1 + -------------------
45 45 * 2*expl(x)
46 46 *
47 47 * expl(x) + 1/expl(x)
48 48 * 0.3465 <= x <= thresh : coshl(x) := -------------------
49 49 * 2
50 50 * thresh <= x <= lnovft : coshl(x) := expl(x)/2
51 51 * lnovft <= x < INF : coshl(x) := scalbnl(expl(x-1024*ln2),1023)
52 52 *
53 53 * here
54 54 * thr1 a number that is near one half of ln2.
55 55 * thr2 a number such that
56 56 * expl(thresh)+expl(-thresh)=expl(thresh)
57 57 * lnovft: logrithm of the overflow threshold
58 58 * = MEP1*ln2 chopped to machine precision.
59 59 * ME maximum exponent
60 60 * MEP1 maximum exponent plus 1
61 61 *
62 62 * Special cases:
63 63 * coshl(x) is |x| if x is +INF, -INF, or NaN.
64 64 * only coshl(0)=1 is exact for finite x.
65 65 */
66 66
67 67 #define ME 16383
68 68 #define MEP1 16384
69 69 #define LNOVFT 1.135652340629414394949193107797076342845e+4L
70 70 /* last 32 bits of LN2HI is zero */
71 71 #define LN2HI 6.931471805599453094172319547495844850203e-0001L
72 72 #define LN2LO 1.667085920830552208890449330400379754169e-0025L
73 73 #define THR1 0.3465L
74 74 #define THR2 45.L
75 75
76 76 static const long double
77 77 half = 0.5L,
78 78 tinyl = 7.5e-37L,
79 79 one = 1.0L,
80 80 ln2hi = LN2HI,
81 81 ln2lo = LN2LO,
82 82 lnovftL = LNOVFT,
83 83 thr1 = THR1,
84 84 thr2 = THR2;
85 85
86 86 long double
87 87 coshl(long double x) {
88 88 long double t, w;
89 89
90 90 w = fabsl(x);
91 91 if (!finitel(w))
92 92 return (w + w); /* x is INF or NaN */
93 93 if (w < thr1) {
94 94 t = w < tinyl ? w : expm1l(w);
95 95 w = one + t;
96 96 if (w != one)
97 97 w = one + (t * t) / (w + w);
98 98 return (w);
99 99 } else if (w < thr2) {
100 100 t = expl(w);
101 101 return (half * (t + one / t));
102 102 } else if (w <= lnovftL)
103 103 return (half * expl(w));
104 104 else {
105 105 return (scalbnl(expl((w - MEP1 * ln2hi) - MEP1 * ln2lo), ME));
106 106 }
107 107 }
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX